ARIMAX/SARIMAX/VAR

Summary

In the previous modeling sections, we analyzed a univariate time series of monthly inflation rates in the United States, calculated from the Consumer Price Index (CPI) data spanning several decades. While ARIMA and SARIMA models provided insights into the inflation trends and seasonal patterns, we aim to enhance our understanding by incorporating endogenous variables into our analysis. Endogenous variables in the context of inflation might include factors like Disposable Income, unemployment rates, Personal Consumption, and major economic policies or events. These variables are determined within the economic system and are influenced by other variables in the system, often demonstrating interdependence and reacting to changes in other economic indicators.

Literature Review

Numerous studies have explored the relationship between macroeconomic indicators and inflation. A study by Sims (1980) introduced the Vector Autoregression (VAR) approach, which has been widely used in economic forecasting and policy analysis. This approach allows for the modeling of the dynamic interaction among multiple macroeconomic variables. Bernanke et al. (1998) further refined the VAR approach by incorporating structural analysis, providing deeper insights into how monetary policy affects the economy, including inflation.

Research by Stock and Watson (1999) demonstrated the predictive power of incorporating multiple macroeconomic variables in forecasting inflation, showing that models with more variables tend to outperform simpler univariate models. This highlights the importance of considering a broad range of economic indicators to understand inflation dynamics more comprehensively.

VAR Model Justification

A VAR model is preferred over simpler ARIMAX models in this context for several reasons:

Simultaneous Modeling of Multiple Time Series: VAR models can simultaneously account for multiple interdependent economic indicators, capturing the complex relationships between them.

Handling Lags Efficiently: VAR models can effectively handle multiple lags in economic data, which is crucial in understanding the delayed effects of economic policies and events on inflation.

Robustness to Missing Data: Given the historical nature of economic data, VAR models can handle instances of missing data more efficiently than ARIMAX models.

Dynamic Relationships: VAR models are well-suited to capture the evolving relationships between economic variables over time, which is essential in understanding how various factors influence inflation.

Methodology

Our analysis will be divided into two parts, using both VAR and ARIMAX models. The first part will forecast monthly inflation rates using historical CPI data, considering various macroeconomic variables as potential predictors. The second part will focus on a more recent period to capture the effects of contemporary economic policies and global events on inflation.

We will also differentiate between VAR and ARIMAX models based on their capacity to handle multiple variables. While the VAR models will consider a broad range of economic indicators, the ARIMAX models will focus on specific variables identified as key influencers of inflation, such as interest rates and unemployment rates.

This approach will enable us to determine the relative impact of different economic factors on inflation and improve our ability to forecast future inflation trends based on current economic conditions.

Time Series Plot

plot.ts(var_ts1 , main = "", xlab = "")

Pair Plot

# create scatterplot matrix using plotly
fig <- plot_ly(
  data = as.data.frame(var_ts1),
  type = "splom",
  diagonal = list(visible = FALSE),
  dimensions = list(
    list(label = "CPI", values = ~CPIAUCSL),
    list(label = "Unemployment", values = ~UNRATE),
    list(label = "DisposableIncome", values = ~DSPIC96),
    list(label = "PersonalConsumption", values = ~PCE),
    list(label = "TreasuryYield", values = ~GS10),
    list(label = "FederalFundsRate", values = ~FEDFUNDS)
  )
) %>%
  layout(hovermode = "x")



# customize layout
fig <- fig %>% 
  layout(
    title = "Scatterplot Matrix of VAR Model Variables",
    xaxis = list(title = ""),
    yaxis = list(title = "")
  )

# display plot
fig
# convert the matrix to a time series object with a yearly frequency
var_ts1 <- ts(var_ts1, frequency = 1,
                 start = 1970)

# split into train and test sets

set.seed(29830)
train_idx <- sample(nrow(var_ts1), 0.9 * nrow(var_ts1))
train <- var_ts1[train_idx, ]
test <- var_ts1[-train_idx, ]

Fitting the VAR Model

Here we use the VARselect() function to find the best p to fit VAR(p). We will choose a maximum lag of 10 and check which p value returns lowest AIC.

(var_result <- VARselect(var_ts1, lag.max = 10, type = "both"))
$selection
AIC(n)  HQ(n)  SC(n) FPE(n) 
     5      3      2      5 

$criteria
                1          2          3          4          5          6
AIC(n)   5.750435   5.112869   5.006714   4.957243   4.953009   4.981328
HQ(n)    5.889067   5.355475   5.353294   5.407796   5.507537   5.639829
SC(n)    6.106319   5.735665   5.896423   6.113864   6.376543   6.671775
FPE(n) 314.330622 166.155229 149.436154 142.249649 141.690540 145.823030
                7          8          9         10
AIC(n)   4.976799   5.018745   5.021673   5.058962
HQ(n)    5.739275   5.885194   5.992096   6.133359
SC(n)    6.934159   7.243017   7.512858   7.817059
FPE(n) 145.249853 151.589710 152.184594 158.160557

Now, we will fit VAR(1), VAR(2), and VAR(3):

VAR(1) output:

summary(fit <- VAR(var_ts1, p=1, type="both"))

VAR Estimation Results:
========================= 
Endogenous variables: CPIAUCSL, UNRATE, DSPIC96, PCE, GS10, FEDFUNDS 
Deterministic variables: both 
Sample size: 600 
Log Likelihood: -6769.181 
Roots of the characteristic polynomial:
0.9993 0.9868 0.9823 0.9823 0.9081 0.9081
Call:
VAR(y = var_ts1, p = 1, type = "both")


Estimation results for equation CPIAUCSL: 
========================================= 
CPIAUCSL = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  9.808e-01  6.108e-03 160.576  < 2e-16 ***
UNRATE.l1    2.348e-02  1.366e-02   1.719  0.08621 .  
DSPIC96.l1   1.807e-04  1.080e-04   1.673  0.09480 .  
PCE.l1      -1.330e-04  5.939e-05  -2.240  0.02546 *  
GS10.l1     -2.084e-02  2.026e-02  -1.028  0.30417    
FEDFUNDS.l1  5.960e-02  1.268e-02   4.700 3.24e-06 ***
const       -2.246e-01  4.949e-01  -0.454  0.65011    
trend        7.612e-03  2.933e-03   2.595  0.00968 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.4126 on 592 degrees of freedom
Multiple R-Squared:     1,  Adjusted R-squared:     1 
F-statistic: 2.193e+06 on 7 and 592 DF,  p-value: < 2.2e-16 


Estimation results for equation UNRATE: 
======================================= 
UNRATE = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  1.187e-02  2.509e-03   4.730 2.81e-06 ***
UNRATE.l1    1.002e+00  5.612e-03 178.637  < 2e-16 ***
DSPIC96.l1   1.674e-04  4.435e-05   3.775 0.000176 ***
PCE.l1      -6.604e-05  2.440e-05  -2.707 0.006986 ** 
GS10.l1     -2.182e-02  8.322e-03  -2.621 0.008983 ** 
FEDFUNDS.l1  2.023e-02  5.209e-03   3.884 0.000114 ***
const       -9.091e-01  2.033e-01  -4.472 9.29e-06 ***
trend       -6.327e-03  1.205e-03  -5.252 2.11e-07 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.1695 on 592 degrees of freedom
Multiple R-Squared: 0.9888, Adjusted R-squared: 0.9887 
F-statistic:  7487 on 7 and 592 DF,  p-value: < 2.2e-16 


Estimation results for equation DSPIC96: 
======================================== 
DSPIC96 = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  -1.863527   1.011445  -1.842  0.06591 .  
UNRATE.l1    -7.201908   2.262177  -3.184  0.00153 ** 
DSPIC96.l1    0.895838   0.017879  50.106  < 2e-16 ***
PCE.l1        0.054053   0.009834   5.496 5.77e-08 ***
GS10.l1       3.917953   3.354882   1.168  0.24334    
FEDFUNDS.l1  -3.606037   2.099888  -1.717  0.08646 .  
const       474.101366  81.949981   5.785 1.17e-08 ***
trend         1.517586   0.485628   3.125  0.00187 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 68.33 on 592 degrees of freedom
Multiple R-Squared: 0.9996, Adjusted R-squared: 0.9996 
F-statistic: 2.212e+05 on 7 and 592 DF,  p-value: < 2.2e-16 


Estimation results for equation PCE: 
==================================== 
PCE = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + const + trend 

             Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1 -1.369810   0.398034  -3.441 0.000619 ***
UNRATE.l1   -0.904493   0.890235  -1.016 0.310037    
DSPIC96.l1   0.004132   0.007036   0.587 0.557198    
PCE.l1       0.996026   0.003870 257.369  < 2e-16 ***
GS10.l1      1.687626   1.320248   1.278 0.201657    
FEDFUNDS.l1 -0.214929   0.826369  -0.260 0.794886    
const       24.072882  32.249800   0.746 0.455692    
trend        0.612548   0.191109   3.205 0.001422 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 26.89 on 592 degrees of freedom
Multiple R-Squared:     1,  Adjusted R-squared:     1 
F-statistic: 2.049e+06 on 7 and 592 DF,  p-value: < 2.2e-16 


Estimation results for equation GS10: 
===================================== 
GS10 = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1 -1.170e-02  4.351e-03  -2.690  0.00734 ** 
UNRATE.l1    9.329e-03  9.731e-03   0.959  0.33810    
DSPIC96.l1  -1.479e-04  7.691e-05  -1.923  0.05498 .  
PCE.l1       3.879e-05  4.230e-05   0.917  0.35958    
GS10.l1      9.608e-01  1.443e-02  66.582  < 2e-16 ***
FEDFUNDS.l1  2.072e-02  9.033e-03   2.293  0.02217 *  
const        9.874e-01  3.525e-01   2.801  0.00526 ** 
trend        6.247e-03  2.089e-03   2.990  0.00290 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.2939 on 592 degrees of freedom
Multiple R-Squared: 0.9909, Adjusted R-squared: 0.9908 
F-statistic:  9169 on 7 and 592 DF,  p-value: < 2.2e-16 


Estimation results for equation FEDFUNDS: 
========================================= 
FEDFUNDS = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1 -3.060e-02  7.902e-03  -3.873 0.000120 ***
UNRATE.l1   -4.754e-02  1.767e-02  -2.690 0.007351 ** 
DSPIC96.l1  -1.187e-04  1.397e-04  -0.850 0.395625    
PCE.l1       5.642e-05  7.683e-05   0.734 0.463016    
GS10.l1      1.016e-01  2.621e-02   3.875 0.000119 ***
FEDFUNDS.l1  9.292e-01  1.640e-02  56.643  < 2e-16 ***
const        1.372e+00  6.402e-01   2.143 0.032557 *  
trend        1.280e-02  3.794e-03   3.375 0.000787 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.5338 on 592 degrees of freedom
Multiple R-Squared: 0.9816, Adjusted R-squared: 0.9814 
F-statistic:  4524 on 7 and 592 DF,  p-value: < 2.2e-16 



Covariance matrix of residuals:
          CPIAUCSL    UNRATE    DSPIC96      PCE      GS10 FEDFUNDS
CPIAUCSL  0.170259 -0.005113   -5.13816   3.9249  0.021823  0.01893
UNRATE   -0.005113  0.028730    0.03106  -0.4434 -0.008505 -0.01666
DSPIC96  -5.138156  0.031063 4668.55214 -37.0247 -0.429415 -0.71821
PCE       3.924950 -0.443416  -37.02471 723.0004  0.555891  0.57875
GS10      0.021823 -0.008505   -0.42941   0.5559  0.086381  0.05497
FEDFUNDS  0.018928 -0.016662   -0.71821   0.5787  0.054966  0.28493

Correlation matrix of residuals:
         CPIAUCSL    UNRATE   DSPIC96      PCE     GS10 FEDFUNDS
CPIAUCSL  1.00000 -0.073101 -0.182247  0.35376  0.17995  0.08594
UNRATE   -0.07310  1.000000  0.002682 -0.09729 -0.17072 -0.18416
DSPIC96  -0.18225  0.002682  1.000000 -0.02015 -0.02138 -0.01969
PCE       0.35376 -0.097292 -0.020153  1.00000  0.07034  0.04032
GS10      0.17995 -0.170723 -0.021383  0.07034  1.00000  0.35036
FEDFUNDS  0.08594 -0.184156 -0.019692  0.04032  0.35036  1.00000

VAR(2) output:

summary(fit <- VAR(var_ts1, p=2, type="both"))

VAR Estimation Results:
========================= 
Endogenous variables: CPIAUCSL, UNRATE, DSPIC96, PCE, GS10, FEDFUNDS 
Deterministic variables: both 
Sample size: 599 
Log Likelihood: -6533.712 
Roots of the characteristic polynomial:
    1 0.9846 0.9683 0.9683 0.9149 0.876 0.4178 0.3643 0.3643 0.2837 0.2198 0.1095
Call:
VAR(y = var_ts1, p = 2, type = "both")


Estimation results for equation CPIAUCSL: 
========================================= 
CPIAUCSL = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  1.332e+00  4.079e-02  32.656  < 2e-16 ***
UNRATE.l1    7.847e-02  9.250e-02   0.848 0.396587    
DSPIC96.l1   1.502e-04  2.279e-04   0.659 0.509913    
PCE.l1       2.146e-03  6.093e-04   3.522 0.000462 ***
GS10.l1      6.798e-02  5.645e-02   1.204 0.228938    
FEDFUNDS.l1  6.398e-02  3.078e-02   2.079 0.038096 *  
CPIAUCSL.l2 -3.472e-01  4.074e-02  -8.523  < 2e-16 ***
UNRATE.l2   -4.980e-02  9.339e-02  -0.533 0.594023    
DSPIC96.l2   6.233e-05  2.281e-04   0.273 0.784786    
PCE.l2      -2.300e-03  6.101e-04  -3.770 0.000180 ***
GS10.l2     -8.981e-02  5.630e-02  -1.595 0.111173    
FEDFUNDS.l2 -2.116e-02  3.080e-02  -0.687 0.492337    
const       -4.592e-01  4.647e-01  -0.988 0.323472    
trend        5.600e-03  2.759e-03   2.029 0.042868 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.3709 on 585 degrees of freedom
Multiple R-Squared:     1,  Adjusted R-squared:     1 
F-statistic: 1.455e+06 on 13 and 585 DF,  p-value: < 2.2e-16 


Estimation results for equation UNRATE: 
======================================= 
UNRATE = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  1.129e-02  1.822e-02   0.620 0.535767    
UNRATE.l1    1.049e+00  4.133e-02  25.382  < 2e-16 ***
DSPIC96.l1   7.986e-05  1.018e-04   0.784 0.433185    
PCE.l1      -1.136e-03  2.722e-04  -4.174 3.44e-05 ***
GS10.l1     -4.383e-02  2.522e-02  -1.738 0.082768 .  
FEDFUNDS.l1 -1.212e-02  1.375e-02  -0.881 0.378787    
CPIAUCSL.l2 -2.694e-03  1.820e-02  -0.148 0.882412    
UNRATE.l2   -4.968e-02  4.173e-02  -1.191 0.234303    
DSPIC96.l2   6.881e-05  1.019e-04   0.675 0.499942    
PCE.l2       1.078e-03  2.726e-04   3.952 8.68e-05 ***
GS10.l2      2.662e-02  2.516e-02   1.058 0.290402    
FEDFUNDS.l2  3.132e-02  1.376e-02   2.276 0.023214 *  
const       -7.552e-01  2.077e-01  -3.637 0.000300 ***
trend       -4.764e-03  1.233e-03  -3.864 0.000124 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.1658 on 585 degrees of freedom
Multiple R-Squared: 0.9894, Adjusted R-squared: 0.9892 
F-statistic:  4207 on 13 and 585 DF,  p-value: < 2.2e-16 


Estimation results for equation DSPIC96: 
======================================== 
DSPIC96 = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + const + trend 

             Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1 -21.71041    7.38894  -2.938  0.00343 ** 
UNRATE.l1   -28.75670   16.75780  -1.716  0.08669 .  
DSPIC96.l1    0.72208    0.04128  17.492  < 2e-16 ***
PCE.l1        0.11559    0.11038   1.047  0.29544    
GS10.l1       9.94580   10.22646   0.973  0.33118    
FEDFUNDS.l1  -4.26814    5.57660  -0.765  0.44436    
CPIAUCSL.l2  20.27753    7.38086   2.747  0.00619 ** 
UNRATE.l2    21.98608   16.91809   1.300  0.19426    
DSPIC96.l2    0.19711    0.04133   4.769 2.34e-06 ***
PCE.l2       -0.07270    0.11053  -0.658  0.51100    
GS10.l2      -5.92789   10.19874  -0.581  0.56130    
FEDFUNDS.l2   1.70186    5.58020   0.305  0.76049    
const       375.76035   84.18901   4.463 9.68e-06 ***
trend         1.17311    0.49986   2.347  0.01926 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 67.2 on 585 degrees of freedom
Multiple R-Squared: 0.9996, Adjusted R-squared: 0.9996 
F-statistic: 1.227e+05 on 13 and 585 DF,  p-value: < 2.2e-16 


Estimation results for equation PCE: 
==================================== 
PCE = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  13.895207   2.877179   4.829 1.75e-06 ***
UNRATE.l1   -17.149924   6.525321  -2.628 0.008809 ** 
DSPIC96.l1    0.006826   0.016075   0.425 0.671268    
PCE.l1        0.831833   0.042980  19.354  < 2e-16 ***
GS10.l1      -1.455403   3.982084  -0.365 0.714879    
FEDFUNDS.l1  -2.117331   2.171472  -0.975 0.329930    
CPIAUCSL.l2 -15.358472   2.874035  -5.344 1.31e-07 ***
UNRATE.l2    16.235457   6.587737   2.464 0.014007 *  
DSPIC96.l2   -0.001770   0.016093  -0.110 0.912473    
PCE.l2        0.163794   0.043040   3.806 0.000156 ***
GS10.l2       3.266601   3.971290   0.823 0.411097    
FEDFUNDS.l2   1.485204   2.172876   0.684 0.494549    
const        22.615719  32.782368   0.690 0.490547    
trend         0.642373   0.194642   3.300 0.001025 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 26.17 on 585 degrees of freedom
Multiple R-Squared:     1,  Adjusted R-squared:     1 
F-statistic: 1.162e+06 on 13 and 585 DF,  p-value: < 2.2e-16 


Estimation results for equation GS10: 
===================================== 
GS10 = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  4.145e-02  3.020e-02   1.373   0.1704    
UNRATE.l1   -1.361e-01  6.849e-02  -1.987   0.0473 *  
DSPIC96.l1   2.064e-05  1.687e-04   0.122   0.9027    
PCE.l1       1.127e-03  4.511e-04   2.499   0.0127 *  
GS10.l1      1.251e+00  4.180e-02  29.923  < 2e-16 ***
FEDFUNDS.l1 -1.862e-02  2.279e-02  -0.817   0.4142    
CPIAUCSL.l2 -4.634e-02  3.017e-02  -1.536   0.1251    
UNRATE.l2    1.554e-01  6.915e-02   2.247   0.0250 *  
DSPIC96.l2  -1.173e-04  1.689e-04  -0.695   0.4875    
PCE.l2      -1.120e-03  4.518e-04  -2.478   0.0135 *  
GS10.l2     -3.150e-01  4.168e-02  -7.557  1.6e-13 ***
FEDFUNDS.l2  4.984e-02  2.281e-02   2.185   0.0293 *  
const        6.527e-01  3.441e-01   1.897   0.0583 .  
trend        3.135e-03  2.043e-03   1.535   0.1254    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.2747 on 585 degrees of freedom
Multiple R-Squared: 0.9921, Adjusted R-squared: 0.9919 
F-statistic:  5659 on 13 and 585 DF,  p-value: < 2.2e-16 


Estimation results for equation FEDFUNDS: 
========================================= 
FEDFUNDS = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1 -0.0456235  0.0510978  -0.893 0.372296    
UNRATE.l1   -0.4759622  0.1158875  -4.107 4.58e-05 ***
DSPIC96.l1  -0.0001574  0.0002855  -0.551 0.581543    
PCE.l1       0.0002825  0.0007633   0.370 0.711414    
GS10.l1      0.5268645  0.0707205   7.450 3.37e-13 ***
FEDFUNDS.l1  1.2355455  0.0385646  32.038  < 2e-16 ***
CPIAUCSL.l2  0.0359225  0.0510419   0.704 0.481847    
UNRATE.l2    0.4448581  0.1169960   3.802 0.000158 ***
DSPIC96.l2   0.0002183  0.0002858   0.764 0.445329    
PCE.l2      -0.0003050  0.0007644  -0.399 0.690043    
GS10.l2     -0.4494898  0.0705288  -6.373 3.76e-10 ***
FEDFUNDS.l2 -0.3013560  0.0385896  -7.809 2.67e-14 ***
const        0.2013182  0.5822041   0.346 0.729628    
trend        0.0029051  0.0034568   0.840 0.401020    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.4647 on 585 degrees of freedom
Multiple R-Squared: 0.9862, Adjusted R-squared: 0.9859 
F-statistic:  3223 on 13 and 585 DF,  p-value: < 2.2e-16 



Covariance matrix of residuals:
          CPIAUCSL    UNRATE    DSPIC96      PCE      GS10  FEDFUNDS
CPIAUCSL  0.137601 -0.001106 -4.549e+00   3.4120  0.010362  0.007159
UNRATE   -0.001106  0.027474 -1.712e-03  -0.5035 -0.005972 -0.009845
DSPIC96  -4.549058 -0.001712  4.516e+03 -14.9202 -0.370402 -1.288496
PCE       3.412025 -0.503523 -1.492e+01 684.7491  0.457156  0.524037
GS10      0.010362 -0.005972 -3.704e-01   0.4572  0.075443  0.038994
FEDFUNDS  0.007159 -0.009845 -1.288e+00   0.5240  0.038994  0.215974

Correlation matrix of residuals:
         CPIAUCSL     UNRATE    DSPIC96       PCE     GS10 FEDFUNDS
CPIAUCSL  1.00000 -0.0179823 -0.1824864  0.351509  0.10170  0.04153
UNRATE   -0.01798  1.0000000 -0.0001537 -0.116089 -0.13118 -0.12781
DSPIC96  -0.18249 -0.0001537  1.0000000 -0.008485 -0.02007 -0.04126
PCE       0.35151 -0.1160891 -0.0084845  1.000000  0.06360  0.04309
GS10      0.10170 -0.1311763 -0.0200670  0.063605  1.00000  0.30548
FEDFUNDS  0.04153 -0.1278084 -0.0412574  0.043092  0.30548  1.00000

VAR(3) output:

summary(fit <- VAR(var_ts1, p=3, type="both"))

VAR Estimation Results:
========================= 
Endogenous variables: CPIAUCSL, UNRATE, DSPIC96, PCE, GS10, FEDFUNDS 
Deterministic variables: both 
Sample size: 598 
Log Likelihood: -6455.747 
Roots of the characteristic polynomial:
    1 0.9822 0.9737 0.9737 0.9449 0.9028 0.5495 0.4541 0.4541 0.4277 0.4277 0.4055 0.3394 0.3394 0.3173 0.3173 0.223 0.223
Call:
VAR(y = var_ts1, p = 3, type = "both")


Estimation results for equation CPIAUCSL: 
========================================= 
CPIAUCSL = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + CPIAUCSL.l3 + UNRATE.l3 + DSPIC96.l3 + PCE.l3 + GS10.l3 + FEDFUNDS.l3 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  1.3999529  0.0442577  31.632  < 2e-16 ***
UNRATE.l1    0.0972676  0.0924184   1.052 0.293024    
DSPIC96.l1   0.0002741  0.0002283   1.201 0.230377    
PCE.l1       0.0023667  0.0006194   3.821 0.000147 ***
GS10.l1      0.0882201  0.0579665   1.522 0.128577    
FEDFUNDS.l1  0.0627856  0.0341177   1.840 0.066242 .  
CPIAUCSL.l2 -0.5854177  0.0684994  -8.546  < 2e-16 ***
UNRATE.l2   -0.0386682  0.1317426  -0.294 0.769235    
DSPIC96.l2   0.0005502  0.0002792   1.971 0.049206 *  
PCE.l2      -0.0018320  0.0007718  -2.373 0.017947 *  
GS10.l2     -0.1320624  0.0883875  -1.494 0.135687    
FEDFUNDS.l2 -0.0014276  0.0521380  -0.027 0.978165    
CPIAUCSL.l3  0.1717438  0.0426604   4.026 6.43e-05 ***
UNRATE.l3   -0.0290749  0.0934086  -0.311 0.755710    
DSPIC96.l3  -0.0006750  0.0002289  -2.950 0.003310 ** 
PCE.l3      -0.0006551  0.0006330  -1.035 0.301204    
GS10.l3      0.0169111  0.0588071   0.288 0.773780    
FEDFUNDS.l3 -0.0133484  0.0323942  -0.412 0.680448    
const       -0.2750833  0.4670350  -0.589 0.556092    
trend        0.0053832  0.0027764   1.939 0.053000 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.3633 on 578 degrees of freedom
Multiple R-Squared:     1,  Adjusted R-squared:     1 
F-statistic: 1.033e+06 on 19 and 578 DF,  p-value: < 2.2e-16 


Estimation results for equation UNRATE: 
======================================= 
UNRATE = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + CPIAUCSL.l3 + UNRATE.l3 + DSPIC96.l3 + PCE.l3 + GS10.l3 + FEDFUNDS.l3 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  2.605e-02  1.973e-02   1.320  0.18722    
UNRATE.l1    1.016e+00  4.120e-02  24.659  < 2e-16 ***
DSPIC96.l1   9.791e-05  1.018e-04   0.962  0.33655    
PCE.l1      -1.204e-03  2.761e-04  -4.361 1.53e-05 ***
GS10.l1     -4.285e-02  2.584e-02  -1.658  0.09781 .  
FEDFUNDS.l1  1.047e-02  1.521e-02   0.688  0.49144    
CPIAUCSL.l2 -2.436e-02  3.054e-02  -0.798  0.42533    
UNRATE.l2    1.524e-01  5.873e-02   2.596  0.00968 ** 
DSPIC96.l2  -5.697e-05  1.244e-04  -0.458  0.64728    
PCE.l2       5.165e-04  3.441e-04   1.501  0.13393    
GS10.l2      4.085e-02  3.941e-02   1.037  0.30034    
FEDFUNDS.l2 -2.391e-02  2.324e-02  -1.029  0.30406    
CPIAUCSL.l3  4.860e-03  1.902e-02   0.256  0.79840    
UNRATE.l3   -1.724e-01  4.164e-02  -4.140 3.99e-05 ***
DSPIC96.l3   8.292e-05  1.020e-04   0.813  0.41673    
PCE.l3       6.388e-04  2.822e-04   2.264  0.02397 *  
GS10.l3     -1.217e-02  2.622e-02  -0.464  0.64274    
FEDFUNDS.l3  3.125e-02  1.444e-02   2.164  0.03088 *  
const       -6.055e-01  2.082e-01  -2.908  0.00378 ** 
trend       -3.654e-03  1.238e-03  -2.952  0.00329 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.162 on 578 degrees of freedom
Multiple R-Squared:  0.99,  Adjusted R-squared: 0.9897 
F-statistic:  3010 on 19 and 578 DF,  p-value: < 2.2e-16 


Estimation results for equation DSPIC96: 
======================================== 
DSPIC96 = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + CPIAUCSL.l3 + UNRATE.l3 + DSPIC96.l3 + PCE.l3 + GS10.l3 + FEDFUNDS.l3 + const + trend 

             Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1 -29.12109    8.10177  -3.594 0.000353 ***
UNRATE.l1   -30.02520   16.91801  -1.775 0.076466 .  
DSPIC96.l1    0.69196    0.04180  16.555  < 2e-16 ***
PCE.l1        0.11451    0.11338   1.010 0.312922    
GS10.l1      11.79430   10.61128   1.111 0.266821    
FEDFUNDS.l1  -6.19385    6.24555  -0.992 0.321749    
CPIAUCSL.l2  37.95807   12.53942   3.027 0.002579 ** 
UNRATE.l2    24.42613   24.11665   1.013 0.311564    
DSPIC96.l2    0.08208    0.05110   1.606 0.108756    
PCE.l2       -0.09091    0.14129  -0.643 0.520201    
GS10.l2      -8.52430   16.18011  -0.527 0.598508    
FEDFUNDS.l2   6.96975    9.54433   0.730 0.465533    
CPIAUCSL.l3 -10.35743    7.80936  -1.326 0.185269    
UNRATE.l3    -1.64514   17.09927  -0.096 0.923386    
DSPIC96.l3    0.15822    0.04189   3.777 0.000175 ***
PCE.l3        0.01317    0.11588   0.114 0.909542    
GS10.l3       2.80167   10.76517   0.260 0.794761    
FEDFUNDS.l3  -4.57569    5.93006  -0.772 0.440660    
const       329.61650   85.49492   3.855 0.000129 ***
trend         1.10550    0.50825   2.175 0.030025 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 66.5 on 578 degrees of freedom
Multiple R-Squared: 0.9996, Adjusted R-squared: 0.9996 
F-statistic: 8.545e+04 on 19 and 578 DF,  p-value: < 2.2e-16 


Estimation results for equation PCE: 
==================================== 
PCE = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + CPIAUCSL.l3 + UNRATE.l3 + DSPIC96.l3 + PCE.l3 + GS10.l3 + FEDFUNDS.l3 + const + trend 

             Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  16.05085    3.17036   5.063 5.56e-07 ***
UNRATE.l1   -16.36366    6.62032  -2.472 0.013733 *  
DSPIC96.l1    0.01171    0.01636   0.716 0.474330    
PCE.l1        0.82297    0.04437  18.549  < 2e-16 ***
GS10.l1      -0.32174    4.15238  -0.077 0.938265    
FEDFUNDS.l1  -1.06643    2.44400  -0.436 0.662749    
CPIAUCSL.l2 -20.50444    4.90690  -4.179 3.39e-05 ***
UNRATE.l2     2.97363    9.43727   0.315 0.752804    
DSPIC96.l2    0.01885    0.02000   0.943 0.346262    
PCE.l2        0.19367    0.05529   3.503 0.000496 ***
GS10.l2      -6.49579    6.33156  -1.026 0.305350    
FEDFUNDS.l2  -0.49691    3.73486  -0.133 0.894203    
CPIAUCSL.l3   3.02337    3.05594   0.989 0.322909    
UNRATE.l3    12.70421    6.69125   1.899 0.058111 .  
DSPIC96.l3   -0.02594    0.01639  -1.582 0.114087    
PCE.l3       -0.02060    0.04535  -0.454 0.649819    
GS10.l3       8.28570    4.21260   1.967 0.049674 *  
FEDFUNDS.l3   1.34115    2.32053   0.578 0.563524    
const        21.37961   33.45567   0.639 0.523048    
trend         0.62832    0.19889   3.159 0.001665 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 26.02 on 578 degrees of freedom
Multiple R-Squared:     1,  Adjusted R-squared:     1 
F-statistic: 8.017e+05 on 19 and 578 DF,  p-value: < 2.2e-16 


Estimation results for equation GS10: 
===================================== 
GS10 = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + CPIAUCSL.l3 + UNRATE.l3 + DSPIC96.l3 + PCE.l3 + GS10.l3 + FEDFUNDS.l3 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  7.595e-02  3.280e-02   2.316  0.02091 *  
UNRATE.l1   -1.345e-01  6.848e-02  -1.965  0.04994 *  
DSPIC96.l1   8.116e-05  1.692e-04   0.480  0.63165    
PCE.l1       1.088e-03  4.590e-04   2.370  0.01811 *  
GS10.l1      1.300e+00  4.295e-02  30.265  < 2e-16 ***
FEDFUNDS.l1  1.310e-02  2.528e-02   0.518  0.60442    
CPIAUCSL.l2 -1.344e-01  5.076e-02  -2.647  0.00834 ** 
UNRATE.l2    2.030e-01  9.762e-02   2.079  0.03806 *  
DSPIC96.l2  -7.918e-05  2.069e-04  -0.383  0.70201    
PCE.l2      -8.839e-04  5.719e-04  -1.545  0.12281    
GS10.l2     -5.622e-01  6.550e-02  -8.584  < 2e-16 ***
FEDFUNDS.l2  2.509e-02  3.863e-02   0.649  0.51628    
CPIAUCSL.l3  5.247e-02  3.161e-02   1.660  0.09747 .  
UNRATE.l3   -5.275e-02  6.922e-02  -0.762  0.44634    
DSPIC96.l3  -1.253e-04  1.696e-04  -0.739  0.46036    
PCE.l3      -1.757e-04  4.691e-04  -0.375  0.70805    
GS10.l3      2.073e-01  4.358e-02   4.757 2.49e-06 ***
FEDFUNDS.l3 -9.962e-03  2.400e-02  -0.415  0.67830    
const        7.471e-01  3.461e-01   2.159  0.03127 *  
trend        3.641e-03  2.057e-03   1.770  0.07733 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.2692 on 578 degrees of freedom
Multiple R-Squared: 0.9925, Adjusted R-squared: 0.9923 
F-statistic:  4032 on 19 and 578 DF,  p-value: < 2.2e-16 


Estimation results for equation FEDFUNDS: 
========================================= 
FEDFUNDS = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + CPIAUCSL.l3 + UNRATE.l3 + DSPIC96.l3 + PCE.l3 + GS10.l3 + FEDFUNDS.l3 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1 -1.087e-02  5.599e-02  -0.194  0.84616    
UNRATE.l1   -4.983e-01  1.169e-01  -4.262 2.37e-05 ***
DSPIC96.l1  -6.070e-05  2.889e-04  -0.210  0.83365    
PCE.l1       1.475e-04  7.836e-04   0.188  0.85077    
GS10.l1      5.137e-01  7.334e-02   7.005 6.88e-12 ***
FEDFUNDS.l1  1.318e+00  4.316e-02  30.538  < 2e-16 ***
CPIAUCSL.l2 -2.474e-02  8.666e-02  -0.285  0.77543    
UNRATE.l2    5.383e-01  1.667e-01   3.230  0.00131 ** 
DSPIC96.l2   3.376e-04  3.532e-04   0.956  0.33946    
PCE.l2      -9.879e-05  9.765e-04  -0.101  0.91945    
GS10.l2     -5.653e-01  1.118e-01  -5.056 5.77e-07 ***
FEDFUNDS.l2 -4.970e-01  6.596e-02  -7.534 1.90e-13 ***
CPIAUCSL.l3  2.421e-02  5.397e-02   0.449  0.65386    
UNRATE.l3   -7.198e-02  1.182e-01  -0.609  0.54271    
DSPIC96.l3  -2.633e-04  2.895e-04  -0.909  0.36357    
PCE.l3      -4.632e-05  8.009e-04  -0.058  0.95390    
GS10.l3      1.205e-01  7.440e-02   1.619  0.10597    
FEDFUNDS.l3  1.221e-01  4.098e-02   2.978  0.00302 ** 
const        4.190e-01  5.909e-01   0.709  0.47857    
trend        3.908e-03  3.513e-03   1.113  0.26630    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.4596 on 578 degrees of freedom
Multiple R-Squared: 0.9867, Adjusted R-squared: 0.9862 
F-statistic:  2254 on 19 and 578 DF,  p-value: < 2.2e-16 



Covariance matrix of residuals:
           CPIAUCSL     UNRATE    DSPIC96      PCE      GS10  FEDFUNDS
CPIAUCSL  0.1319789 -0.0009514   -3.73603   3.2543  0.007906  0.005619
UNRATE   -0.0009514  0.0262322   -0.03135  -0.4439 -0.006329 -0.011396
DSPIC96  -3.7360288 -0.0313497 4422.68797  13.7281 -0.167113 -0.932497
PCE       3.2543067 -0.4439276   13.72809 677.2438  0.300133  0.388906
GS10      0.0079055 -0.0063292   -0.16711   0.3001  0.072468  0.036450
FEDFUNDS  0.0056189 -0.0113963   -0.93250   0.3889  0.036450  0.211253

Correlation matrix of residuals:
         CPIAUCSL    UNRATE   DSPIC96       PCE      GS10 FEDFUNDS
CPIAUCSL  1.00000 -0.016170 -0.154637  0.344218  0.080836  0.03365
UNRATE   -0.01617  1.000000 -0.002911 -0.105323 -0.145164 -0.15309
DSPIC96  -0.15464 -0.002911  1.000000  0.007932 -0.009335 -0.03051
PCE       0.34422 -0.105323  0.007932  1.000000  0.042842  0.03251
GS10      0.08084 -0.145164 -0.009335  0.042842  1.000000  0.29459
FEDFUNDS  0.03365 -0.153089 -0.030507  0.032514  0.294595  1.00000

K-Fold Cross Validation and Model Diagnostics

# Define the number of folds for cross-validation
k <- 5

# Define the p values to test
p_values <- c(1, 2, 3)

# Split the data into k folds
cv_folds <- cut(seq(1, nrow(var_ts1)), breaks = k, labels = FALSE)

# Initialize vectors to store RMSE and AIC values for each p value
rmse_vec <- numeric(length(p_values))
aic_vec <- numeric(length(p_values))

# Loop over p values and perform cross-validation
for (i in seq_along(p_values)) {
  p <- p_values[i]
  rmse_cv <- numeric(k)
  aic_cv <- numeric(k)
  for (j in 1:k) {
    # Split the data into training and testing sets
    train <- var_ts1[cv_folds != j, ]
    test <- var_ts1[cv_folds == j, ]
    
    # Fit the VAR model with the current p value
    var_fit <- VAR(train, p = p)
    
    # Make predictions for the testing set
    pred <- predict(var_fit, n.ahead = nrow(test))$fcst
    
    # Calculate RMSE and AIC for the current fold
    rmse_cv[j] <- sqrt(mean((pred$CPIAUCSL - test[,1])^2))
    aic_cv[j] <- AIC(var_fit)
  }
  # Calculate the mean RMSE and AIC across all folds for the current p value
  rmse_vec[i] <- mean(rmse_cv)
  aic_vec[i] <- mean(aic_cv)
}

# Create a table of RMSE and AIC values for each p value
results_table <- tibble(p_values, rmse_vec, aic_vec)

# Print the results table
kable(results_table, format = "markdown", 
        col.names = c("P Values", "Mean RMSE (5 Folds)", "Mean AIC (5 Folds)"), align = "c", digits = 2
        )
P Values Mean RMSE (5 Folds) Mean AIC (5 Folds)
1 151.16 11942.99
2 145.37 11658.50
3 144.87 11587.17

The VAR(3) model outputs the lowest Mean RMSE of 144.87 inflation from the 5-fold cross validation. However, it has the highest AIC score. Because test set performance is best and it is the simplest model, we shall choose the VAR(3) model as the best option.

Forecasting the chosen model (P=3)

final_var <- VAR(var_ts1, p = 3)

(fit.pr = predict(final_var, n.ahead = 5, ci = 0.95)) # 5 years ahead 
$CPIAUCSL
         fcst    lower    upper       CI
[1,] 259.3881 258.6743 260.1018 0.713728
[2,] 259.8701 258.5939 261.1463 1.276158
[3,] 260.3400 258.6425 262.0376 1.697582
[4,] 260.7761 258.7572 262.7949 2.018880
[5,] 261.2104 258.9234 263.4973 2.286950

$UNRATE
         fcst    lower    upper        CI
[1,] 3.482483 3.162932 3.802033 0.3195505
[2,] 3.462199 2.991376 3.933021 0.4708229
[3,] 3.476632 2.842868 4.110396 0.6337641
[4,] 3.489748 2.715837 4.263658 0.7739103
[5,] 3.513099 2.612477 4.413721 0.9006220

$DSPIC96
         fcst    lower    upper       CI
[1,] 15887.36 15756.60 16018.13 130.7634
[2,] 15906.22 15742.93 16069.51 163.2903
[3,] 15948.27 15766.61 16129.92 181.6532
[4,] 15986.92 15786.95 16186.88 199.9637
[5,] 16022.93 15806.49 16239.36 216.4349

$PCE
         fcst    lower    upper        CI
[1,] 14855.74 14804.34 14907.14  51.39997
[2,] 14908.94 14837.64 14980.25  71.30850
[3,] 14956.63 14865.87 15047.38  90.75522
[4,] 15003.92 14897.13 15110.71 106.78949
[5,] 15050.73 14929.64 15171.82 121.09257

$GS10
         fcst     lower    upper        CI
[1,] 1.715155 1.1865638 2.243747 0.5285914
[2,] 1.689191 0.7992903 2.579092 0.8899010
[3,] 1.667817 0.5549866 2.780648 1.1128308
[4,] 1.630803 0.3630515 2.898554 1.2677513
[5,] 1.588605 0.1911054 2.986104 1.3974992

$FEDFUNDS
         fcst       lower    upper        CI
[1,] 1.517328  0.61629815 2.418358 0.9010301
[2,] 1.552455 -0.05806836 3.162979 1.6105236
[3,] 1.591517 -0.53307984 3.716113 2.1245965
[4,] 1.593517 -0.90452339 4.091558 2.4980406
[5,] 1.579673 -1.20701980 4.366366 2.7866927
fanchart(fit.pr) # plot prediction + error

The above plot showcases the forecasts for each variable present in the VAR(3) model, Yearly Inflation, Unemployment, Personal Consumption, Treasury Yield and Federal Funds Rate. The predicted forecast, from the years 2021 to 2025, for CPI is a good sign for the US due to the rising trend.

Let us visualize more closely the forecasts for the CPI from 2021 to 2025, corresponding to the VAR(3) model fitted on all years (1970-2020):

df_fvar_attack <- as.data.frame(fit.pr$fcst$CPIAUCSL)
# add year column
df_fvar_attack$Year <- c("2021", "2022", "2023", "2024", "2025")
(var_plot <- ggplot(data=df_fvar_attack, aes(x=Year, y=fcst, group = 1)) +
    geom_line(aes(color="Forecast"), linewidth=1) +
    geom_ribbon(aes(ymin=lower, ymax=upper, fill="Confidence Interval"), alpha=0.1) +
    labs(title="VAR(3) Forecasts for CPI from 2021 to 2025",
         y="CPI",
         color="", fill="",
         caption="Data Sources: FRED") +
    scale_color_manual(values = c("Forecast"="red")) +
    scale_fill_manual(values = c("95% Confidence Interval"="steelblue")) +
    theme_minimal() + 
  theme(plot.caption.position = "plot"))

Building the VAR Model (Post COVID-19)

Time Series Plot

plot.ts(var_ts2 , main = "", xlab = "")

Pair Plots

# create scatterplot matrix using plotly
fig <- plot_ly(
  data = as.data.frame(var_ts2), 
  type = "splom",
  diagonal = list(visible = FALSE),
  dimensions = list(
    list(label = "CPI", values = ~CPIAUCSL),
    list(label = "Unemployment", values = ~UNRATE),
    list(label = "DisposableIncome", values = ~DSPIC96),
    list(label = "PersonalConsumption", values = ~PCE),
    list(label = "TreasuryYield", values = ~GS10),
    list(label = "FederalFundsRate", values = ~FEDFUNDS)
  )
) %>%
  layout(hovermode = "x")

fig <- fig %>% 
  layout(
    title = "Scatterplot Matrix of VAR Model Variables (Post COVID-19)",
    xaxis = list(title = ""),
    yaxis = list(title = "")
  )

# display plot
fig

Fitting the VAR Model

Here we use the VARselect() function to find the best p to fit VAR(p). We will choose a maximum lag of 10 and check which p value returns lowest AIC.

(var_result <- VARselect(var_ts2, lag.max = 10, type = "both"))
$selection
AIC(n)  HQ(n)  SC(n) FPE(n) 
    10      4      2     10 

$criteria
                  1           2           3           4           5           6
AIC(n)     12.10596    10.67409    10.54164    10.43213    10.43372    10.42279
HQ(n)      12.23718    10.90373    10.86970    10.85861    10.95863    11.04611
SC(n)      12.44385    11.26540    11.38636    11.53027    11.78529    12.02776
FPE(n) 180947.94882 43223.11299 37864.33401 33941.84237 34004.38817 33646.23719
                 7           8           9          10
AIC(n)    10.40910    10.41932    10.37218    10.33357
HQ(n)     11.13084    11.23949    11.29077    11.35058
SC(n)     12.26750    12.53113    12.73741    12.95222
FPE(n) 33204.88543 33567.30729 32047.59811 30864.68386

Now, we will fit VAR(1), VAR(2), and VAR(3):

VAR(1) output:

summary(fit <- VAR(var_ts2, p=1, type="both"))

VAR Estimation Results:
========================= 
Endogenous variables: CPIAUCSL, UNRATE, DSPIC96, PCE, GS10, FEDFUNDS 
Deterministic variables: both 
Sample size: 641 
Log Likelihood: -9274.084 
Roots of the characteristic polynomial:
0.999 0.9974 0.9974 0.9575 0.9152 0.6585
Call:
VAR(y = var_ts2, p = 1, type = "both")


Estimation results for equation CPIAUCSL: 
========================================= 
CPIAUCSL = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  1.004e+00  5.422e-03 185.098   <2e-16 ***
UNRATE.l1   -4.642e-03  1.376e-02  -0.337   0.7360    
DSPIC96.l1   1.140e-04  6.431e-05   1.773   0.0768 .  
PCE.l1       6.650e-05  3.760e-05   1.769   0.0775 .  
GS10.l1      2.405e-02  2.320e-02   1.037   0.3002    
FEDFUNDS.l1  2.948e-02  1.441e-02   2.045   0.0413 *  
const       -5.464e-01  3.362e-01  -1.625   0.1046    
trend       -4.218e-03  2.366e-03  -1.783   0.0751 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.49 on 633 degrees of freedom
Multiple R-Squared:     1,  Adjusted R-squared:     1 
F-statistic: 1.952e+06 on 7 and 633 DF,  p-value: < 2.2e-16 


Estimation results for equation UNRATE: 
======================================= 
UNRATE = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1 -7.237e-04  5.114e-03  -0.142   0.8875    
UNRATE.l1    9.644e-01  1.298e-02  74.289   <2e-16 ***
DSPIC96.l1  -9.547e-05  6.066e-05  -1.574   0.1160    
PCE.l1       3.030e-05  3.546e-05   0.854   0.3932    
GS10.l1     -1.413e-02  2.188e-02  -0.646   0.5188    
FEDFUNDS.l1  1.259e-02  1.360e-02   0.926   0.3547    
const        6.086e-01  3.171e-01   1.919   0.0554 .  
trend        1.350e-03  2.232e-03   0.605   0.5453    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.4622 on 633 degrees of freedom
Multiple R-Squared: 0.9264, Adjusted R-squared: 0.9256 
F-statistic:  1139 on 7 and 633 DF,  p-value: < 2.2e-16 


Estimation results for equation DSPIC96: 
======================================== 
DSPIC96 = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  -12.55136    2.56069  -4.902 1.21e-06 ***
UNRATE.l1      4.17093    6.50028   0.642    0.521    
DSPIC96.l1     0.68905    0.03037  22.687  < 2e-16 ***
PCE.l1         0.13983    0.01776   7.875 1.49e-14 ***
GS10.l1      -17.75539   10.95601  -1.621    0.106    
FEDFUNDS.l1   10.10453    6.80730   1.484    0.138    
const       1503.78315  158.78407   9.471  < 2e-16 ***
trend          7.70122    1.11749   6.892 1.34e-11 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 231.4 on 633 degrees of freedom
Multiple R-Squared: 0.9965, Adjusted R-squared: 0.9964 
F-statistic: 2.559e+04 on 7 and 633 DF,  p-value: < 2.2e-16 


Estimation results for equation PCE: 
==================================== 
PCE = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  2.903e+00  1.071e+00   2.710 0.006911 ** 
UNRATE.l1    9.673e+00  2.719e+00   3.558 0.000402 ***
DSPIC96.l1   7.236e-02  1.270e-02   5.696 1.88e-08 ***
PCE.l1       9.703e-01  7.427e-03 130.635  < 2e-16 ***
GS10.l1     -2.477e+00  4.583e+00  -0.541 0.589006    
FEDFUNDS.l1  2.484e+00  2.847e+00   0.872 0.383275    
const       -3.949e+02  6.642e+01  -5.946 4.53e-09 ***
trend       -1.752e+00  4.674e-01  -3.748 0.000195 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 96.8 on 633 degrees of freedom
Multiple R-Squared: 0.9996, Adjusted R-squared: 0.9996 
F-statistic: 2.233e+05 on 7 and 633 DF,  p-value: < 2.2e-16 


Estimation results for equation GS10: 
===================================== 
GS10 = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1 -2.657e-03  3.239e-03  -0.820   0.4123    
UNRATE.l1    7.473e-03  8.222e-03   0.909   0.3637    
DSPIC96.l1  -6.607e-05  3.841e-05  -1.720   0.0859 .  
PCE.l1       3.731e-05  2.246e-05   1.661   0.0972 .  
GS10.l1      9.671e-01  1.386e-02  69.788   <2e-16 ***
FEDFUNDS.l1  1.724e-02  8.610e-03   2.003   0.0456 *  
const        4.340e-01  2.008e-01   2.161   0.0311 *  
trend        1.281e-03  1.413e-03   0.907   0.3650    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.2927 on 633 degrees of freedom
Multiple R-Squared: 0.9915, Adjusted R-squared: 0.9914 
F-statistic: 1.05e+04 on 7 and 633 DF,  p-value: < 2.2e-16 


Estimation results for equation FEDFUNDS: 
========================================= 
FEDFUNDS = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1 -1.242e-02  5.813e-03  -2.137  0.03296 *  
UNRATE.l1   -4.563e-02  1.476e-02  -3.092  0.00207 ** 
DSPIC96.l1  -3.499e-05  6.895e-05  -0.507  0.61201    
PCE.l1       8.068e-05  4.031e-05   2.001  0.04577 *  
GS10.l1      1.006e-01  2.487e-02   4.044  5.9e-05 ***
FEDFUNDS.l1  9.305e-01  1.545e-02  60.214  < 2e-16 ***
const        5.428e-01  3.604e-01   1.506  0.13259    
trend        3.728e-03  2.537e-03   1.469  0.14219    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.5253 on 633 degrees of freedom
Multiple R-Squared: 0.9823, Adjusted R-squared: 0.9821 
F-statistic:  5030 on 7 and 633 DF,  p-value: < 2.2e-16 



Covariance matrix of residuals:
          CPIAUCSL    UNRATE   DSPIC96      PCE     GS10 FEDFUNDS
CPIAUCSL   0.24013  -0.05535   -15.686   16.695  0.03101  0.02665
UNRATE    -0.05535   0.21361    36.255  -32.261 -0.01421 -0.03240
DSPIC96  -15.68635  36.25500 53555.024 -571.886 -1.06595 -3.35790
PCE       16.69544 -32.26071  -571.886 9369.730  3.31255  5.74350
GS10       0.03101  -0.01421    -1.066    3.313  0.08567  0.05487
FEDFUNDS   0.02665  -0.03240    -3.358    5.744  0.05487  0.27597

Correlation matrix of residuals:
         CPIAUCSL  UNRATE  DSPIC96      PCE     GS10 FEDFUNDS
CPIAUCSL   1.0000 -0.2444 -0.13833  0.35198  0.21621  0.10354
UNRATE    -0.2444  1.0000  0.33897 -0.72110 -0.10500 -0.13344
DSPIC96   -0.1383  0.3390  1.00000 -0.02553 -0.01574 -0.02762
PCE        0.3520 -0.7211 -0.02553  1.00000  0.11692  0.11295
GS10       0.2162 -0.1050 -0.01574  0.11692  1.00000  0.35682
FEDFUNDS   0.1035 -0.1334 -0.02762  0.11295  0.35682  1.00000

VAR(2) output:

summary(fit <- VAR(var_ts2, p=2, type="both"))

VAR Estimation Results:
========================= 
Endogenous variables: CPIAUCSL, UNRATE, DSPIC96, PCE, GS10, FEDFUNDS 
Deterministic variables: both 
Sample size: 640 
Log Likelihood: -8765.803 
Roots of the characteristic polynomial:
1.002 0.9938 0.976 0.9665 0.8687 0.8687 0.5569 0.4755 0.439 0.439 0.3769 0.3769
Call:
VAR(y = var_ts2, p = 2, type = "both")


Estimation results for equation CPIAUCSL: 
========================================= 
CPIAUCSL = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  1.4215516  0.0379593  37.449  < 2e-16 ***
UNRATE.l1    0.1853689  0.0597027   3.105  0.00199 ** 
DSPIC96.l1  -0.0000137  0.0000832  -0.165  0.86928    
PCE.l1       0.0011975  0.0002791   4.290 2.07e-05 ***
GS10.l1      0.1185237  0.0627596   1.889  0.05942 .  
FEDFUNDS.l1  0.0646079  0.0344637   1.875  0.06130 .  
CPIAUCSL.l2 -0.4220773  0.0380908 -11.081  < 2e-16 ***
UNRATE.l2   -0.1829256  0.0605829  -3.019  0.00264 ** 
DSPIC96.l2   0.0001004  0.0000787   1.275  0.20264    
PCE.l2      -0.0011885  0.0002694  -4.411 1.21e-05 ***
GS10.l2     -0.1108661  0.0627963  -1.765  0.07797 .  
FEDFUNDS.l2 -0.0468105  0.0341387  -1.371  0.17081    
const       -0.3101875  0.3341981  -0.928  0.35368    
trend       -0.0012712  0.0022396  -0.568  0.57051    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.4232 on 626 degrees of freedom
Multiple R-Squared:     1,  Adjusted R-squared:     1 
F-statistic: 1.403e+06 on 13 and 626 DF,  p-value: < 2.2e-16 


Estimation results for equation UNRATE: 
======================================= 
UNRATE = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  3.780e-02  3.322e-02   1.138 0.255642    
UNRATE.l1    3.118e-01  5.225e-02   5.967 4.05e-09 ***
DSPIC96.l1   2.553e-04  7.281e-05   3.507 0.000486 ***
PCE.l1      -4.257e-03  2.443e-04 -17.428  < 2e-16 ***
GS10.l1     -1.138e-01  5.492e-02  -2.072 0.038711 *  
FEDFUNDS.l1 -7.030e-02  3.016e-02  -2.331 0.020081 *  
CPIAUCSL.l2 -2.805e-02  3.333e-02  -0.841 0.400461    
UNRATE.l2    6.658e-01  5.302e-02  12.558  < 2e-16 ***
DSPIC96.l2  -8.537e-05  6.888e-05  -1.239 0.215657    
PCE.l2       4.201e-03  2.358e-04  17.816  < 2e-16 ***
GS10.l2      9.876e-02  5.495e-02   1.797 0.072785 .  
FEDFUNDS.l2  9.394e-02  2.988e-02   3.144 0.001744 ** 
const       -7.496e-01  2.925e-01  -2.563 0.010604 *  
trend       -5.475e-03  1.960e-03  -2.793 0.005374 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.3704 on 626 degrees of freedom
Multiple R-Squared: 0.9532, Adjusted R-squared: 0.9522 
F-statistic: 980.7 on 13 and 626 DF,  p-value: < 2.2e-16 


Estimation results for equation DSPIC96: 
======================================== 
DSPIC96 = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  -19.45821   16.87132  -1.153   0.2492    
UNRATE.l1   -134.95087   26.53532  -5.086 4.85e-07 ***
DSPIC96.l1     0.44313    0.03698  11.984  < 2e-16 ***
PCE.l1        -1.13145    0.12407  -9.120  < 2e-16 ***
GS10.l1        3.50497   27.89400   0.126   0.9000    
FEDFUNDS.l1   -7.43573   15.31766  -0.485   0.6275    
CPIAUCSL.l2   16.36520   16.92976   0.967   0.3341    
UNRATE.l2    134.87420   26.92654   5.009 7.13e-07 ***
DSPIC96.l2     0.48497    0.03498  13.864  < 2e-16 ***
PCE.l2         1.16933    0.11974   9.765  < 2e-16 ***
GS10.l2       -9.15256   27.91032  -0.328   0.7431    
FEDFUNDS.l2   13.54166   15.17323   0.892   0.3725    
const        368.11628  148.53700   2.478   0.0135 *  
trend          1.88999    0.99539   1.899   0.0581 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 188.1 on 626 degrees of freedom
Multiple R-Squared: 0.9977, Adjusted R-squared: 0.9976 
F-statistic: 2.082e+04 on 13 and 626 DF,  p-value: < 2.2e-16 


Estimation results for equation PCE: 
==================================== 
PCE = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1    4.83697    7.72100   0.626 0.531236    
UNRATE.l1    152.54985   12.14365  12.562  < 2e-16 ***
DSPIC96.l1    -0.02646    0.01692  -1.563 0.118449    
PCE.l1         1.61059    0.05678  28.366  < 2e-16 ***
GS10.l1       21.97184   12.76543   1.721 0.085709 .  
FEDFUNDS.l1   10.72636    7.00999   1.530 0.126483    
CPIAUCSL.l2   -3.98752    7.74775  -0.515 0.606967    
UNRATE.l2   -146.96614   12.32268 -11.926  < 2e-16 ***
DSPIC96.l2     0.05725    0.01601   3.576 0.000376 ***
PCE.l2        -0.62567    0.05480 -11.418  < 2e-16 ***
GS10.l2      -21.16124   12.77290  -1.657 0.098075 .  
FEDFUNDS.l2  -12.19515    6.94389  -1.756 0.079536 .  
const       -167.34735   67.97660  -2.462 0.014091 *  
trend         -0.54154    0.45553  -1.189 0.234964    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 86.08 on 626 degrees of freedom
Multiple R-Squared: 0.9997, Adjusted R-squared: 0.9997 
F-statistic: 1.517e+05 on 13 and 626 DF,  p-value: < 2.2e-16 


Estimation results for equation GS10: 
===================================== 
GS10 = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  6.550e-02  2.465e-02   2.657  0.00809 ** 
UNRATE.l1    7.839e-03  3.877e-02   0.202  0.83985    
DSPIC96.l1  -2.594e-05  5.403e-05  -0.480  0.63134    
PCE.l1       4.549e-05  1.813e-04   0.251  0.80194    
GS10.l1      1.270e+00  4.076e-02  31.161  < 2e-16 ***
FEDFUNDS.l1 -8.618e-03  2.238e-02  -0.385  0.70032    
CPIAUCSL.l2 -6.637e-02  2.474e-02  -2.683  0.00749 ** 
UNRATE.l2    6.638e-03  3.934e-02   0.169  0.86607    
DSPIC96.l2  -5.303e-05  5.111e-05  -1.038  0.29989    
PCE.l2      -2.424e-05  1.750e-04  -0.139  0.88985    
GS10.l2     -3.264e-01  4.078e-02  -8.004 5.85e-15 ***
FEDFUNDS.l2  3.381e-02  2.217e-02   1.525  0.12780    
const        4.882e-01  2.170e-01   2.249  0.02484 *  
trend        1.047e-03  1.454e-03   0.720  0.47177    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.2748 on 626 degrees of freedom
Multiple R-Squared: 0.9926, Adjusted R-squared: 0.9924 
F-statistic:  6417 on 13 and 626 DF,  p-value: < 2.2e-16 


Estimation results for equation FEDFUNDS: 
========================================= 
FEDFUNDS = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1 -2.041e-02  4.121e-02  -0.495   0.6207    
UNRATE.l1   -1.106e-01  6.482e-02  -1.706   0.0884 .  
DSPIC96.l1   6.588e-05  9.033e-05   0.729   0.4661    
PCE.l1      -3.047e-04  3.031e-04  -1.005   0.3152    
GS10.l1      5.524e-01  6.814e-02   8.107 2.74e-15 ***
FEDFUNDS.l1  1.266e+00  3.742e-02  33.828  < 2e-16 ***
CPIAUCSL.l2  1.813e-02  4.136e-02   0.438   0.6613    
UNRATE.l2    7.872e-02  6.578e-02   1.197   0.2319    
DSPIC96.l2  -2.405e-05  8.545e-05  -0.281   0.7785    
PCE.l2       3.212e-04  2.925e-04   1.098   0.2726    
GS10.l2     -4.702e-01  6.818e-02  -6.897 1.30e-11 ***
FEDFUNDS.l2 -3.376e-01  3.707e-02  -9.108  < 2e-16 ***
const        5.425e-02  3.629e-01   0.150   0.8812    
trend       -3.988e-04  2.432e-03  -0.164   0.8698    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.4595 on 626 degrees of freedom
Multiple R-Squared: 0.9866, Adjusted R-squared: 0.9863 
F-statistic:  3550 on 13 and 626 DF,  p-value: < 2.2e-16 



Covariance matrix of residuals:
         CPIAUCSL     UNRATE   DSPIC96      PCE      GS10 FEDFUNDS
CPIAUCSL  0.17910  -0.016725    -7.566   10.897  0.016536  0.01143
UNRATE   -0.01672   0.137164    13.924  -21.288 -0.006801 -0.02031
DSPIC96  -7.56559  13.924086 35380.471 1741.521  1.640781 -1.27537
PCE      10.89689 -21.288001  1741.521 7409.914  2.247045  4.56767
GS10      0.01654  -0.006801     1.641    2.247  0.075540  0.03990
FEDFUNDS  0.01143  -0.020314    -1.275    4.568  0.039898  0.21114

Correlation matrix of residuals:
         CPIAUCSL   UNRATE  DSPIC96      PCE     GS10 FEDFUNDS
CPIAUCSL  1.00000 -0.10671 -0.09504  0.29912  0.14217  0.05877
UNRATE   -0.10671  1.00000  0.19988 -0.66774 -0.06682 -0.11937
DSPIC96  -0.09504  0.19988  1.00000  0.10756  0.03174 -0.01476
PCE       0.29912 -0.66774  0.10756  1.00000  0.09498  0.11548
GS10      0.14217 -0.06682  0.03174  0.09498  1.00000  0.31592
FEDFUNDS  0.05877 -0.11937 -0.01476  0.11548  0.31592  1.00000

VAR(3) output:

summary(fit <- VAR(var_ts2, p=3, type="both"))

VAR Estimation Results:
========================= 
Endogenous variables: CPIAUCSL, UNRATE, DSPIC96, PCE, GS10, FEDFUNDS 
Deterministic variables: both 
Sample size: 639 
Log Likelihood: -8674.334 
Roots of the characteristic polynomial:
1.002 0.9966 0.9822 0.9673 0.8943 0.8943 0.5423 0.5423 0.5056 0.5056 0.4748 0.4748 0.4181 0.4181 0.244 0.244 0.07907 0.06819
Call:
VAR(y = var_ts2, p = 3, type = "both")


Estimation results for equation CPIAUCSL: 
========================================= 
CPIAUCSL = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + CPIAUCSL.l3 + UNRATE.l3 + DSPIC96.l3 + PCE.l3 + GS10.l3 + FEDFUNDS.l3 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  1.455e+00  4.345e-02  33.483  < 2e-16 ***
UNRATE.l1    2.048e-01  6.736e-02   3.041  0.00246 ** 
DSPIC96.l1  -3.795e-05  9.929e-05  -0.382  0.70245    
PCE.l1       1.214e-03  2.990e-04   4.059 5.56e-05 ***
GS10.l1      1.449e-01  6.554e-02   2.211  0.02743 *  
FEDFUNDS.l1  5.266e-02  3.901e-02   1.350  0.17754    
CPIAUCSL.l2 -5.571e-01  7.115e-02  -7.830 2.13e-14 ***
UNRATE.l2   -2.003e-01  8.964e-02  -2.234  0.02581 *  
DSPIC96.l2   6.915e-05  9.327e-05   0.741  0.45877    
PCE.l2      -1.008e-03  4.604e-04  -2.189  0.02900 *  
GS10.l2     -1.549e-01  1.006e-01  -1.540  0.12406    
FEDFUNDS.l2 -4.306e-03  6.025e-02  -0.071  0.94304    
CPIAUCSL.l3  1.032e-01  4.211e-02   2.451  0.01452 *  
UNRATE.l3   -5.081e-03  6.993e-02  -0.073  0.94210    
DSPIC96.l3   6.730e-05  9.161e-05   0.735  0.46285    
PCE.l3      -1.957e-04  3.403e-04  -0.575  0.56531    
GS10.l3      2.370e-02  6.698e-02   0.354  0.72355    
FEDFUNDS.l3 -3.266e-02  3.706e-02  -0.882  0.37838    
const       -3.892e-01  3.517e-01  -1.107  0.26884    
trend       -2.102e-03  2.339e-03  -0.899  0.36922    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.423 on 619 degrees of freedom
Multiple R-Squared:     1,  Adjusted R-squared:     1 
F-statistic: 9.571e+05 on 19 and 619 DF,  p-value: < 2.2e-16 


Estimation results for equation UNRATE: 
======================================= 
UNRATE = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + CPIAUCSL.l3 + UNRATE.l3 + DSPIC96.l3 + PCE.l3 + GS10.l3 + FEDFUNDS.l3 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  7.876e-02  3.753e-02   2.099  0.03624 *  
UNRATE.l1    2.777e-01  5.818e-02   4.774 2.26e-06 ***
DSPIC96.l1   3.058e-04  8.575e-05   3.566  0.00039 ***
PCE.l1      -4.667e-03  2.583e-04 -18.068  < 2e-16 ***
GS10.l1     -1.161e-01  5.660e-02  -2.051  0.04072 *  
FEDFUNDS.l1 -4.357e-02  3.370e-02  -1.293  0.19643    
CPIAUCSL.l2 -1.153e-01  6.145e-02  -1.876  0.06113 .  
UNRATE.l2    9.307e-01  7.742e-02  12.022  < 2e-16 ***
DSPIC96.l2  -2.363e-04  8.056e-05  -2.933  0.00348 ** 
PCE.l2       5.164e-03  3.976e-04  12.987  < 2e-16 ***
GS10.l2      1.165e-01  8.685e-02   1.342  0.18024    
FEDFUNDS.l2  3.070e-02  5.204e-02   0.590  0.55544    
CPIAUCSL.l3  4.385e-02  3.637e-02   1.206  0.22838    
UNRATE.l3   -2.365e-01  6.039e-02  -3.916  0.00010 ***
DSPIC96.l3   5.552e-05  7.912e-05   0.702  0.48314    
PCE.l3      -5.290e-04  2.939e-04  -1.800  0.07235 .  
GS10.l3     -9.171e-03  5.785e-02  -0.159  0.87408    
FEDFUNDS.l3  3.308e-02  3.200e-02   1.034  0.30166    
const       -5.142e-01  3.037e-01  -1.693  0.09093 .  
trend       -4.222e-03  2.020e-03  -2.090  0.03705 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.3653 on 619 degrees of freedom
Multiple R-Squared: 0.9549, Adjusted R-squared: 0.9535 
F-statistic: 689.6 on 19 and 619 DF,  p-value: < 2.2e-16 


Estimation results for equation DSPIC96: 
======================================== 
DSPIC96 = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + CPIAUCSL.l3 + UNRATE.l3 + DSPIC96.l3 + PCE.l3 + GS10.l3 + FEDFUNDS.l3 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1   -2.84105   19.15148  -0.148 0.882118    
UNRATE.l1   -175.64362   29.69048  -5.916 5.47e-09 ***
DSPIC96.l1     0.38830    0.04376   8.873  < 2e-16 ***
PCE.l1        -1.19554    0.13181  -9.070  < 2e-16 ***
GS10.l1       11.43483   28.88638   0.396 0.692348    
FEDFUNDS.l1  -12.30414   17.19537  -0.716 0.474539    
CPIAUCSL.l2  -15.35811   31.35946  -0.490 0.624489    
UNRATE.l2    134.52057   39.50940   3.405 0.000705 ***
DSPIC96.l2     0.49485    0.04111  12.037  < 2e-16 ***
PCE.l2         0.75594    0.20292   3.725 0.000213 ***
GS10.l2      -16.45059   44.32124  -0.371 0.710640    
FEDFUNDS.l2   17.17192   26.55585   0.647 0.518108    
CPIAUCSL.l3   16.39397   18.56128   0.883 0.377452    
UNRATE.l3     39.16077   30.82043   1.271 0.204344    
DSPIC96.l3     0.07422    0.04038   1.838 0.066492 .  
PCE.l3         0.46848    0.14997   3.124 0.001869 ** 
GS10.l3        2.12261   29.52092   0.072 0.942703    
FEDFUNDS.l3    0.61079   16.33225   0.037 0.970180    
const        229.41415  154.99244   1.480 0.139338    
trend          1.08535    1.03104   1.053 0.292900    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 186.4 on 619 degrees of freedom
Multiple R-Squared: 0.9978, Adjusted R-squared: 0.9977 
F-statistic: 1.445e+04 on 19 and 619 DF,  p-value: < 2.2e-16 


Estimation results for equation PCE: 
==================================== 
PCE = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + CPIAUCSL.l3 + UNRATE.l3 + DSPIC96.l3 + PCE.l3 + GS10.l3 + FEDFUNDS.l3 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1   10.31227    8.80046   1.172 0.241734    
UNRATE.l1    134.95588   13.64333   9.892  < 2e-16 ***
DSPIC96.l1    -0.04224    0.02011  -2.101 0.036073 *  
PCE.l1         1.57997    0.06057  26.086  < 2e-16 ***
GS10.l1       25.32738   13.27383   1.908 0.056845 .  
FEDFUNDS.l1    8.18212    7.90159   1.036 0.300839    
CPIAUCSL.l2  -10.24779   14.41026  -0.711 0.477262    
UNRATE.l2   -143.31706   18.15531  -7.894 1.34e-14 ***
DSPIC96.l2     0.06398    0.01889   3.387 0.000751 ***
PCE.l2        -0.78580    0.09324  -8.427 2.48e-16 ***
GS10.l2      -29.36288   20.36644  -1.442 0.149885    
FEDFUNDS.l2   -6.73688   12.20291  -0.552 0.581099    
CPIAUCSL.l3    1.17986    8.52926   0.138 0.890024    
UNRATE.l3     13.17155   14.16257   0.930 0.352720    
DSPIC96.l3     0.01923    0.01855   1.036 0.300392    
PCE.l3         0.18779    0.06892   2.725 0.006613 ** 
GS10.l3        6.21115   13.56542   0.458 0.647209    
FEDFUNDS.l3   -3.55427    7.50498  -0.474 0.635961    
const       -213.76325   71.22194  -3.001 0.002796 ** 
trend         -0.80677    0.47378  -1.703 0.089100 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 85.67 on 619 degrees of freedom
Multiple R-Squared: 0.9997, Adjusted R-squared: 0.9997 
F-statistic: 1.045e+05 on 19 and 619 DF,  p-value: < 2.2e-16 


Estimation results for equation GS10: 
===================================== 
GS10 = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + CPIAUCSL.l3 + UNRATE.l3 + DSPIC96.l3 + PCE.l3 + GS10.l3 + FEDFUNDS.l3 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  1.057e-01  2.760e-02   3.831 0.000141 ***
UNRATE.l1   -3.024e-02  4.278e-02  -0.707 0.479956    
DSPIC96.l1   3.271e-05  6.306e-05   0.519 0.604131    
PCE.l1      -6.582e-05  1.899e-04  -0.347 0.729053    
GS10.l1      1.318e+00  4.162e-02  31.658  < 2e-16 ***
FEDFUNDS.l1  1.692e-02  2.478e-02   0.683 0.494916    
CPIAUCSL.l2 -1.467e-01  4.519e-02  -3.246 0.001232 ** 
UNRATE.l2    2.460e-02  5.693e-02   0.432 0.665769    
DSPIC96.l2  -2.008e-05  5.924e-05  -0.339 0.734755    
PCE.l2       1.131e-05  2.924e-04   0.039 0.969154    
GS10.l2     -5.874e-01  6.386e-02  -9.197  < 2e-16 ***
FEDFUNDS.l2  1.828e-02  3.827e-02   0.478 0.632935    
CPIAUCSL.l3  3.899e-02  2.675e-02   1.458 0.145383    
UNRATE.l3    1.759e-02  4.441e-02   0.396 0.692251    
DSPIC96.l3  -9.884e-05  5.818e-05  -1.699 0.089843 .  
PCE.l3       8.885e-05  2.161e-04   0.411 0.681090    
GS10.l3      2.230e-01  4.254e-02   5.242 2.18e-07 ***
FEDFUNDS.l3 -1.294e-02  2.353e-02  -0.550 0.582740    
const        5.077e-01  2.233e-01   2.273 0.023345 *  
trend        1.378e-03  1.486e-03   0.928 0.353938    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.2686 on 619 degrees of freedom
Multiple R-Squared: 0.993,  Adjusted R-squared: 0.9927 
F-statistic:  4597 on 19 and 619 DF,  p-value: < 2.2e-16 


Estimation results for equation FEDFUNDS: 
========================================= 
FEDFUNDS = CPIAUCSL.l1 + UNRATE.l1 + DSPIC96.l1 + PCE.l1 + GS10.l1 + FEDFUNDS.l1 + CPIAUCSL.l2 + UNRATE.l2 + DSPIC96.l2 + PCE.l2 + GS10.l2 + FEDFUNDS.l2 + CPIAUCSL.l3 + UNRATE.l3 + DSPIC96.l3 + PCE.l3 + GS10.l3 + FEDFUNDS.l3 + const + trend 

              Estimate Std. Error t value Pr(>|t|)    
CPIAUCSL.l1  2.062e-02  4.670e-02   0.442  0.65889    
UNRATE.l1   -1.674e-01  7.239e-02  -2.312  0.02110 *  
DSPIC96.l1   1.188e-04  1.067e-04   1.114  0.26582    
PCE.l1      -5.239e-04  3.214e-04  -1.630  0.10360    
GS10.l1      5.419e-01  7.043e-02   7.693 5.68e-14 ***
FEDFUNDS.l1  1.339e+00  4.193e-02  31.941  < 2e-16 ***
CPIAUCSL.l2 -4.525e-02  7.646e-02  -0.592  0.55423    
UNRATE.l2    1.624e-01  9.633e-02   1.686  0.09225 .  
DSPIC96.l2  -3.545e-05  1.002e-04  -0.354  0.72373    
PCE.l2       4.968e-04  4.948e-04   1.004  0.31575    
GS10.l2     -5.942e-01  1.081e-01  -5.499 5.60e-08 ***
FEDFUNDS.l2 -5.150e-01  6.475e-02  -7.953 8.68e-15 ***
CPIAUCSL.l3  2.110e-02  4.526e-02   0.466  0.64114    
UNRATE.l3   -2.912e-02  7.515e-02  -0.388  0.69850    
DSPIC96.l3  -6.282e-05  9.845e-05  -0.638  0.52365    
PCE.l3       6.049e-05  3.657e-04   0.165  0.86866    
GS10.l3      1.297e-01  7.198e-02   1.802  0.07208 .  
FEDFUNDS.l3  1.110e-01  3.982e-02   2.786  0.00549 ** 
const        1.694e-01  3.779e-01   0.448  0.65413    
trend        1.320e-04  2.514e-03   0.053  0.95814    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.4546 on 619 degrees of freedom
Multiple R-Squared: 0.987,  Adjusted R-squared: 0.9866 
F-statistic:  2481 on 19 and 619 DF,  p-value: < 2.2e-16 



Covariance matrix of residuals:
         CPIAUCSL     UNRATE   DSPIC96      PCE      GS10 FEDFUNDS
CPIAUCSL  0.17893  -0.016960    -7.857   11.013  0.015729  0.01174
UNRATE   -0.01696   0.133468    13.591  -21.714 -0.007292 -0.02283
DSPIC96  -7.85739  13.590859 34759.020 1384.812  1.438151 -1.60584
PCE      11.01265 -21.714480  1384.812 7339.628  2.122663  4.45476
GS10      0.01573  -0.007292     1.438    2.123  0.072170  0.03731
FEDFUNDS  0.01174  -0.022825    -1.606    4.455  0.037308  0.20665

Correlation matrix of residuals:
         CPIAUCSL  UNRATE  DSPIC96      PCE     GS10 FEDFUNDS
CPIAUCSL  1.00000 -0.1098 -0.09963  0.30389  0.13841  0.06107
UNRATE   -0.10975  1.0000  0.19954 -0.69378 -0.07430 -0.13744
DSPIC96  -0.09963  0.1995  1.00000  0.08670  0.02871 -0.01895
PCE       0.30389 -0.6938  0.08670  1.00000  0.09223  0.11439
GS10      0.13841 -0.0743  0.02871  0.09223  1.00000  0.30550
FEDFUNDS  0.06107 -0.1374 -0.01895  0.11439  0.30550  1.00000

K-Fold Cross Validation and Model Diagnostics

# Define the number of folds for cross-validation
k <- 5

# Define the p values to test
p_values <- c(1, 2, 3)

# Split the data into k folds
cv_folds <- cut(seq(1, nrow(var_ts2)), breaks = k, labels = FALSE)

# Initialize vectors to store RMSE and AIC values for each p value
rmse_vec <- numeric(length(p_values))
aic_vec <- numeric(length(p_values))

# Loop over p values and perform cross-validation
for (i in seq_along(p_values)) {
  p <- p_values[i]
  rmse_cv <- numeric(k)
  aic_cv <- numeric(k)
  for (j in 1:k) {
    # Split the data into training and testing sets
    train <- var_ts2[cv_folds != j, ]
    test <- var_ts2[cv_folds == j, ]
    
    # Fit the VAR model with the current p value
    var_fit <- VAR(train, p = p)
    
    # Make predictions for the testing set
    pred <- predict(var_fit, n.ahead = nrow(test))$fcst
    
    # Calculate RMSE and AIC for the current fold
    rmse_cv[j] <- sqrt(mean((pred$CPIAUCSL - test[,1])^2))
    aic_cv[j] <- AIC(var_fit)
  }
  # Calculate the mean RMSE and AIC across all folds for the current p value
  rmse_vec[i] <- mean(rmse_cv)
  aic_vec[i] <- mean(aic_cv)
}

# Create a table of RMSE and AIC values for each p value
results_table <- tibble(p_values, rmse_vec, aic_vec)

# Print the results table
kable(results_table, format = "markdown", 
        col.names = c("P Values", "Mean RMSE (5 Folds)", "Mean AIC (5 Folds)"), align = "c", digits = 2
        )
P Values Mean RMSE (5 Folds) Mean AIC (5 Folds)
1 214.07 15472.03
2 197.77 14821.86
3 202.50 14714.38

The VAR(2) model outputs the lowest Mean RMSE of 197.84 from the 5-fold cross validation. However, it has the highest AIC score. Because predictive performance is best and it is the simplest model, we shall choose the VAR(2) model as the best option.

Forecasting the chosen model (P=2)

final_var <- VAR(var_ts2, p = 2)

(fit.pr = predict(final_var, n.ahead = 5, ci = 0.95)) # 5 years ahead 
$CPIAUCSL
         fcst    lower    upper        CI
[1,] 304.5980 303.7690 305.4270 0.8290186
[2,] 305.3897 303.8877 306.8916 1.5019366
[3,] 306.2069 304.1124 308.3014 2.0945028
[4,] 307.0482 304.4439 309.6525 2.6043236
[5,] 307.9016 304.8500 310.9531 3.0515667

$UNRATE
         fcst    lower    upper       CI
[1,] 3.668710 2.938897 4.398523 0.729813
[2,] 3.896853 2.746868 5.046838 1.149985
[3,] 4.091349 2.702882 5.479815 1.388466
[4,] 4.241375 2.694821 5.787928 1.546553
[5,] 4.385280 2.700831 6.069729 1.684449

$DSPIC96
         fcst    lower    upper       CI
[1,] 16925.05 16555.62 17294.47 369.4284
[2,] 17011.23 16589.17 17433.30 422.0644
[3,] 17104.42 16609.96 17598.88 494.4611
[4,] 17175.07 16644.95 17705.19 530.1203
[5,] 17252.02 16681.60 17822.45 570.4264

$PCE
         fcst    lower    upper       CI
[1,] 18508.30 18339.53 18677.07 168.7710
[2,] 18515.66 18239.26 18792.06 276.4016
[3,] 18540.34 18202.74 18877.95 337.6041
[4,] 18572.68 18194.11 18951.25 378.5740
[5,] 18606.08 18190.87 19021.29 415.2084

$GS10
         fcst    lower    upper        CI
[1,] 3.806431 3.267952 4.344910 0.5384791
[2,] 3.832180 2.955379 4.708980 0.8768005
[3,] 3.844942 2.710557 4.979328 1.1343854
[4,] 3.852638 2.512646 5.192629 1.3399920
[5,] 3.856427 2.344649 5.368205 1.5117781

$FEDFUNDS
         fcst    lower    upper        CI
[1,] 5.076313 4.176405 5.976221 0.8999079
[2,] 5.015310 3.460506 6.570113 1.5548037
[3,] 4.911707 2.823874 6.999540 2.0878330
[4,] 4.787958 2.272402 7.303515 2.5155566
[5,] 4.660179 1.798935 7.521422 2.8612435
fanchart(fit.pr) # plot prediction + error

The above plot showcases the forecasts for each variable present in the VAR(2) model, Yearly Inflation, Unemployment, Personal Consumption, Treasury Yield and Federal Funds Rate. The above plot showcases the forecasts for each variable present in the VAR(3) model, Yearly Inflation, Unemployment, Personal Consumption, Treasury Yield and Federal Funds Rate. The predicted forecast, from the years 2021 to 2025, for CPI is a good sign for the US due to the rising trend.

Let us visualize more closely the forecasts for the CPI from 2021 to 2025, corresponding to the VAR(2) model fitted on Pre COVID-19 and post-COVID-19 years (2001-2020):

df_fvar_attack <- as.data.frame(fit.pr$fcst$CPIAUCSL)
# add year column
df_fvar_attack$Year <- c("2021", "2022", "2023", "2024", "2025")
(var_plot <- ggplot(data=df_fvar_attack, aes(x=Year, y=fcst, group = 1)) +
    geom_line(aes(color="Forecast"), linewidth=1) +
    geom_ribbon(aes(ymin=lower, ymax=upper, fill="Confidence Interval"), alpha=0.1) +
    labs(title="VAR(3) Forecasts for CPI from 2021 to 2025",
         y="CPI",
         color="", fill="",
         caption="Data Sources: FRED") +
    scale_color_manual(values = c("Forecast"="red")) +
    scale_fill_manual(values = c("95% Confidence Interval"="steelblue")) +
    theme_minimal() + 
  theme(plot.caption.position = "plot"))

Manual ARIMAX Modelling (1970-2020: Pre COVID)

The ARIMAX model being analyzed in this section is:

CPI ~ Unemployment Rate + Disposable Income + Personal Consumption + Treasury Yield + Federal Funds Rate

Regression Summary and Fitting ARIMA to Residuals

fit.reg <- lm(CPIAUCSL ~ ., data =var_ts1)
summary(fit.reg)

Call:
lm(formula = CPIAUCSL ~ ., data = var_ts1)

Residuals:
     Min       1Q   Median       3Q      Max 
-22.2129  -6.5241  -0.9476   5.3942  22.4885 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept) -1.175e+02  5.669e+00 -20.732  < 2e-16 ***
UNRATE       1.303e+00  2.764e-01   4.713 3.05e-06 ***
DSPIC96      3.523e-02  1.272e-03  27.691  < 2e-16 ***
PCE         -1.216e-02  1.071e-03 -11.350  < 2e-16 ***
GS10         3.938e+00  3.860e-01  10.200  < 2e-16 ***
FEDFUNDS    -1.170e+00  2.574e-01  -4.545 6.65e-06 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 8.533 on 595 degrees of freedom
Multiple R-squared:  0.9835,    Adjusted R-squared:  0.9834 
F-statistic:  7096 on 5 and 595 DF,  p-value: < 2.2e-16
res.fit<-ts(residuals(fit.reg),star=decimal_date(as.Date("1970-01-01",format = "%Y-%m-%d")),frequency = 1)

# Then look at the residuals 
res.fit %>% ggtsdisplay() # no need to difference

#q=1,3 Q=1 , p=1,2, P=1,2
#write a funtion
SARIMA.c=function(p1,p2,q1,q2,P1,P2,Q1,Q2,d1,d2,data){
  
  temp=c()
  d=0
  D=0
  s=12
  
  i=1
  temp= data.frame()
  ls=matrix(rep(NA,9*44),nrow=44)
  
  
  for (p in p1:p2)
  {
    for(q in q1:q2)
    {
      for(P in P1:P2)
      {
        for(Q in Q1:Q2)
        {
          for(d in d1:d2)
       
        {
          if(p+d+q+P+D+Q<=8)
          {
            
            model<- Arima(data,order=c(p-1,d,q-1),seasonal=c(P-1,D,Q-1))
            ls[i,]= c(p-1,d,q-1,P-1,D,Q-1,model$aic,model$bic,model$aicc)
            i=i+1
            #print(i)
            
          }
          
        }
      }
    }
    
  }
  
  }
  temp= as.data.frame(ls)
  names(temp)= c("p","d","q","P","D","Q","AIC","BIC","AICc")
  
  temp
  
}

##q=1,3 Q=0 p=1,2 P=0 d=0

output=SARIMA.c(p1=1,p2=3,q1=1,q2=4,P1=1,P2=3,Q1=1,Q2=2,d1=0,d2=0,data=res.fit)
output
   p d q P D Q      AIC      BIC     AICc
1  0 0 0 0 0 0 4280.507 4289.305 4280.527
2  0 0 0 0 0 1 4280.507 4289.305 4280.527
3  0 0 0 1 0 0 4280.507 4289.305 4280.527
4  0 0 0 1 0 1 4280.507 4289.305 4280.527
5  0 0 0 2 0 0 4280.507 4289.305 4280.527
6  0 0 0 2 0 1 4280.507 4289.305 4280.527
7  0 0 1 0 0 0 3716.284 3729.480 3716.324
8  0 0 1 0 0 1 3716.284 3729.480 3716.324
9  0 0 1 1 0 0 3716.284 3729.480 3716.324
10 0 0 1 1 0 1 3716.284 3729.480 3716.324
11 0 0 1 2 0 0 3716.284 3729.480 3716.324
12 0 0 1 2 0 1 3716.284 3729.480 3716.324
13 0 0 2 0 0 0 3435.150 3452.744 3435.217
14 0 0 2 0 0 1 3435.150 3452.744 3435.217
15 0 0 2 1 0 0 3435.150 3452.744 3435.217
16 0 0 2 1 0 1 3435.150 3452.744 3435.217
17 0 0 2 2 0 0 3435.150 3452.744 3435.217
18 0 0 3 0 0 0 3276.820 3298.813 3276.921
19 0 0 3 0 0 1 3276.820 3298.813 3276.921
20 0 0 3 1 0 0 3276.820 3298.813 3276.921
21 1 0 0 0 0 0 2942.581 2955.776 2942.621
22 1 0 0 0 0 1 2942.581 2955.776 2942.621
23 1 0 0 1 0 0 2942.581 2955.776 2942.621
24 1 0 0 1 0 1 2942.581 2955.776 2942.621
25 1 0 0 2 0 0 2942.581 2955.776 2942.621
26 1 0 0 2 0 1 2942.581 2955.776 2942.621
27 1 0 1 0 0 0 2939.053 2956.648 2939.121
28 1 0 1 0 0 1 2939.053 2956.648 2939.121
29 1 0 1 1 0 0 2939.053 2956.648 2939.121
30 1 0 1 1 0 1 2939.053 2956.648 2939.121
31 1 0 1 2 0 0 2939.053 2956.648 2939.121
32 1 0 2 0 0 0 2924.167 2946.160 2924.268
33 1 0 2 0 0 1 2924.167 2946.160 2924.268
34 1 0 2 1 0 0 2924.167 2946.160 2924.268
35 1 0 3 0 0 0 2923.576 2949.968 2923.718
36 2 0 0 0 0 0 2940.801 2958.395 2940.868
37 2 0 0 0 0 1 2940.801 2958.395 2940.868
38 2 0 0 1 0 0 2940.801 2958.395 2940.868
39 2 0 0 1 0 1 2940.801 2958.395 2940.868
40 2 0 0 2 0 0 2940.801 2958.395 2940.868
41 2 0 1 0 0 0 2926.113 2948.106 2926.214
42 2 0 1 0 0 1 2926.113 2948.106 2926.214
43 2 0 1 1 0 0 2926.113 2948.106 2926.214
44 2 0 2 0 0 0 2923.837 2950.229 2923.979

ARIMA(1,0,3)

output[which.min(output$AIC),] 
   p d q P D Q      AIC      BIC     AICc
35 1 0 3 0 0 0 2923.576 2949.968 2923.718
output[which.min(output$BIC),]
   p d q P D Q      AIC     BIC     AICc
32 1 0 2 0 0 0 2924.167 2946.16 2924.268
output[which.min(output$AICc),]
   p d q P D Q      AIC      BIC     AICc
35 1 0 3 0 0 0 2923.576 2949.968 2923.718

Model Diagnostics

model_outputar2 <- capture.output(sarima(res.fit, 1,0,3, 0,0,0))

cat(model_outputar2[57:89], model_outputar2[length(model_outputar2)], sep = "\n")
iter  27 value 1.003339
iter  28 value 1.003338
iter  29 value 1.003338
iter  30 value 1.003338
iter  30 value 1.003338
iter  30 value 1.003338
final  value 1.003338 
converged
$fit

Call:
arima(x = xdata, order = c(p, d, q), seasonal = list(order = c(P, D, Q), period = S), 
    xreg = xmean, include.mean = FALSE, transform.pars = trans, fixed = fixed, 
    optim.control = list(trace = trc, REPORT = 1, reltol = tol))

Coefficients:
         ar1      ma1      ma2      ma3   xmean
      0.9784  -0.1445  -0.1657  -0.0644  -0.557
s.e.  0.0091   0.0418   0.0428   0.0400   3.008

sigma^2 estimated as 7.409:  log likelihood = -1455.79,  aic = 2923.58

$degrees_of_freedom
[1] 596

$ttable
      Estimate     SE  t.value p.value
ar1     0.9784 0.0091 107.3409  0.0000
ma1    -0.1445 0.0418  -3.4592  0.0006
ma2    -0.1657 0.0428  -3.8684  0.0001
ma3    -0.0644 0.0400  -1.6100  0.1079
xmean  -0.5570 3.0080  -0.1852  0.8532
arimaModel_1 <- arima(res.fit, order = c(1,0,3))
forecast1=predict(arimaModel_1, 5)
# create df with fcast preds and +-1.96 SE for 95% CI Bands
farimax_df <- data.frame(
  Year = 2021:2025,
  fcst = as.numeric(forecast1$pred),
  lower = as.numeric(forecast1$pred - 1.96 * forecast1$se),
  upper = as.numeric(forecast1$pred + 1.96 * forecast1$se)
)


(arimax_plot <- ggplot(data=farimax_df, aes(x=Year, y=fcst, group = 1)) +
    geom_line(aes(color="Forecast"), linewidth=1) +
    geom_ribbon(aes(ymin=lower, ymax=upper, fill="Confidence Interval"), alpha=0.1) +
    labs(title="ARIMA(1,0,3) Forecasts for CPI from 2021 to 2025",
         y="CPI",
         color="", fill="",
         caption="Data Sources: FRED") +
    scale_color_manual(values = c("Forecast"="red")) +
    scale_fill_manual(values = c("95% Confidence Interval"="steelblue")) +
    theme_minimal() + 
  theme(plot.caption.position = "plot", plot.caption = element_text(size=8)))

Manual ARIMAX Modelling (2020-2023: Post COVID-19 )

The ARIMAX model being analyzed in this section is:

CPI ~ Unemployment Rate + Disposable Income + Personal Consumption + Treasury Yield + Federal Funds Rate

Regression Summary and Fitting ARIMA to Residuals

fit.reg <- lm(CPIAUCSL ~ ., data =var_ts2)
summary(fit.reg)

Call:
lm(formula = CPIAUCSL ~ ., data = var_ts2)

Residuals:
    Min      1Q  Median      3Q     Max 
-92.110  -8.310   1.465   8.365  23.493 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept) -3.943e+01  4.893e+00  -8.057 3.86e-15 ***
UNRATE      -1.008e+00  3.170e-01  -3.179  0.00155 ** 
DSPIC96      1.763e-02  8.892e-04  19.828  < 2e-16 ***
PCE          2.064e-03  7.002e-04   2.948  0.00331 ** 
GS10         6.466e+00  4.687e-01  13.797  < 2e-16 ***
FEDFUNDS    -2.986e+00  3.140e-01  -9.510  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 11.43 on 636 degrees of freedom
Multiple R-squared:  0.9748,    Adjusted R-squared:  0.9746 
F-statistic:  4919 on 5 and 636 DF,  p-value: < 2.2e-16
res.fit<-ts(residuals(fit.reg),star=decimal_date(as.Date("1970-01-01",format = "%Y-%m-%d")),frequency = 1)

# Then look at the residuals 
res.fit %>% ggtsdisplay() # no need to difference

#q=1,3 Q=1 , p=1,2, P=1,2
#write a funtion
SARIMA.c=function(p1,p2,q1,q2,P1,P2,Q1,Q2,d1,d2,data){
  
  temp=c()
  d=0
  D=0
  s=12
  
  i=1
  temp= data.frame()
  ls=matrix(rep(NA,9*44),nrow=44)
  
  
  for (p in p1:p2)
  {
    for(q in q1:q2)
    {
      for(P in P1:P2)
      {
        for(Q in Q1:Q2)
        {
          for(d in d1:d2)
       
        {
          if(p+d+q+P+D+Q<=8)
          {
            
            model<- Arima(data,order=c(p-1,d,q-1),seasonal=c(P-1,D,Q-1))
            ls[i,]= c(p-1,d,q-1,P-1,D,Q-1,model$aic,model$bic,model$aicc)
            i=i+1
            #print(i)
            
          }
          
        }
      }
    }
    
  }
  
  }
  temp= as.data.frame(ls)
  names(temp)= c("p","d","q","P","D","Q","AIC","BIC","AICc")
  
  temp
  
}

##q=1,2 Q=0 , p=1,2 P=0 d=0

output=SARIMA.c(p1=1,p2=3,q1=1,q2=4,P1=1,P2=3,Q1=1,Q2=2,d1=0,d2=0,data=res.fit)
output
   p d q P D Q      AIC      BIC     AICc
1  0 0 0 0 0 0 4947.866 4956.796 4947.885
2  0 0 0 0 0 1 4947.866 4956.796 4947.885
3  0 0 0 1 0 0 4947.866 4956.796 4947.885
4  0 0 0 1 0 1 4947.866 4956.796 4947.885
5  0 0 0 2 0 0 4947.866 4956.796 4947.885
6  0 0 0 2 0 1 4947.866 4956.796 4947.885
7  0 0 1 0 0 0 4496.989 4510.383 4497.027
8  0 0 1 0 0 1 4496.989 4510.383 4497.027
9  0 0 1 1 0 0 4496.989 4510.383 4497.027
10 0 0 1 1 0 1 4496.989 4510.383 4497.027
11 0 0 1 2 0 0 4496.989 4510.383 4497.027
12 0 0 1 2 0 1 4496.989 4510.383 4497.027
13 0 0 2 0 0 0 4203.872 4221.731 4203.935
14 0 0 2 0 0 1 4203.872 4221.731 4203.935
15 0 0 2 1 0 0 4203.872 4221.731 4203.935
16 0 0 2 1 0 1 4203.872 4221.731 4203.935
17 0 0 2 2 0 0 4203.872 4221.731 4203.935
18 0 0 3 0 0 0 4039.712 4062.035 4039.807
19 0 0 3 0 0 1 4039.712 4062.035 4039.807
20 0 0 3 1 0 0 4039.712 4062.035 4039.807
21 1 0 0 0 0 0 3812.180 3825.574 3812.218
22 1 0 0 0 0 1 3812.180 3825.574 3812.218
23 1 0 0 1 0 0 3812.180 3825.574 3812.218
24 1 0 0 1 0 1 3812.180 3825.574 3812.218
25 1 0 0 2 0 0 3812.180 3825.574 3812.218
26 1 0 0 2 0 1 3812.180 3825.574 3812.218
27 1 0 1 0 0 0 3714.614 3732.473 3714.677
28 1 0 1 0 0 1 3714.614 3732.473 3714.677
29 1 0 1 1 0 0 3714.614 3732.473 3714.677
30 1 0 1 1 0 1 3714.614 3732.473 3714.677
31 1 0 1 2 0 0 3714.614 3732.473 3714.677
32 1 0 2 0 0 0 3712.704 3735.027 3712.799
33 1 0 2 0 0 1 3712.704 3735.027 3712.799
34 1 0 2 1 0 0 3712.704 3735.027 3712.799
35 1 0 3 0 0 0 3692.626 3719.414 3692.758
36 2 0 0 0 0 0 3703.861 3721.719 3703.924
37 2 0 0 0 0 1 3703.861 3721.719 3703.924
38 2 0 0 1 0 0 3703.861 3721.719 3703.924
39 2 0 0 1 0 1 3703.861 3721.719 3703.924
40 2 0 0 2 0 0 3703.861 3721.719 3703.924
41 2 0 1 0 0 0 3705.857 3728.180 3705.952
42 2 0 1 0 0 1 3705.857 3728.180 3705.952
43 2 0 1 1 0 0 3705.857 3728.180 3705.952
44 2 0 2 0 0 0 3707.542 3734.330 3707.675

output[which.min(output$AIC),] 
   p d q P D Q      AIC      BIC     AICc
35 1 0 3 0 0 0 3692.626 3719.414 3692.758
output[which.min(output$BIC),]
   p d q P D Q      AIC      BIC     AICc
35 1 0 3 0 0 0 3692.626 3719.414 3692.758
output[which.min(output$AICc),]
   p d q P D Q      AIC      BIC     AICc
35 1 0 3 0 0 0 3692.626 3719.414 3692.758
model_outputma2 <- capture.output(sarima(res.fit, 1,0,3,0,0,0))

cat(model_outputma2[57:89], model_outputma2[length(model_outputar2)], sep = "\n")
$fit

Call:
arima(x = xdata, order = c(p, d, q), seasonal = list(order = c(P, D, Q), period = S), 
    xreg = xmean, include.mean = FALSE, transform.pars = trans, fixed = fixed, 
    optim.control = list(trace = trc, REPORT = 1, reltol = tol))

Coefficients:
         ar1      ma1     ma2     ma3    xmean
      0.9771  -0.4537  0.1864  -0.196  -0.2391
s.e.  0.0091   0.0402  0.0458   0.041   3.6951

sigma^2 estimated as 18.02:  log likelihood = -1840.31,  aic = 3692.63

$degrees_of_freedom
[1] 637

$ttable
      Estimate     SE  t.value p.value
ar1     0.9771 0.0091 107.5191  0.0000
ma1    -0.4537 0.0402 -11.2978  0.0000
ma2     0.1864 0.0458   4.0690  0.0001
ma3    -0.1960 0.0410  -4.7836  0.0000
xmean  -0.2391 3.6951  -0.0647  0.9484

$AIC
[1] 5.751754

$AICc
[1] 5.751901

$BIC
[1] 5.793479
NA
arimaModel_1 <- arima(res.fit, order = c(1,0,3))
forecast1=predict(arimaModel_1, 5)
# create df with fcast preds and +-1.96 SE for 95% CI Bands
farimax_df <- data.frame(
  Year = 2021:2025,
  fcst = as.numeric(forecast1$pred),
  lower = as.numeric(forecast1$pred - 1.96 * forecast1$se),
  upper = as.numeric(forecast1$pred + 1.96 * forecast1$se)
)

#plot(forecast1$pred, main = "ARIMA(2,0,0) Forecast For 5 Years", xlab = "Time", ylab = "Values", col = "red")
(arimax_plot <- ggplot(data=farimax_df, aes(x=Year, y=fcst, group = 1)) +
    geom_line(aes(color="Forecast"), linewidth=1) +
    geom_ribbon(aes(ymin=lower, ymax=upper, fill="Confidence Interval"), alpha=0.1) +
    labs(title="ARIMA(1,0,3) Forecasts for CPI from 2021 to 2025",
         y="CPI",
         color="", fill="",
         caption="Data Sources: FRED") +
    scale_color_manual(values = c("Forecast"="red")) +
    scale_fill_manual(values = c("95% Confidence Interval"="steelblue")) +
    theme_minimal() + 
  theme(plot.caption.position = "plot", plot.caption = element_text(size=8)))

Final Results: Unveiling the Impact of Post-COVID Data on Economic Forecasting: Insights from VAR(2) and ARIMAX Models

The Emergence of VAR(2) as the Front-Runner in Post-Pandemic Economic Forecasting In the realm of economic forecasting, the COVID-19 pandemic has catalyzed a paradigm shift, challenging conventional models and necessitating a reevaluation of data relevance. Our analysis reveals a compelling narrative: the Vector Autoregression (VAR) model, specifically VAR(2), emerges as a beacon of adaptability and accuracy in this new economic era.

Key Findings:

VAR(2) Model Proficiency: The VAR(2) model, utilizing data exclusively from the post-COVID era, significantly outstripped other models in forecasting accuracy. This model adeptly captured the increasing economic trends unique to this period, underscoring its ability to adapt to rapid changes.

Post-COVID Data’s Preeminence: The analysis underscores the importance of focusing on recent, post-pandemic data. Traditional datasets, encompassing years prior to COVID-19, now offer less predictive value for current and future economic states. This shift is vividly reflected in the performance leap of the VAR(2) model, which thrives on post-COVID data.

Comparing VAR(2) with ARIMAX Models: A Tale of Two Methodologies

Our journey into economic forecasting doesn’t end with VAR models. A comparison with ARIMAX (Autoregressive Integrated Moving Average with Exogenous Variables) models painted a nuanced picture:

ARIMAX Model Disparities: Models trained on all-inclusive data spanning from 1970 to 2020 paled in comparison to those trained solely on post-COVID data. This was particularly evident in the leap in adjusted R-squared values, indicating a more accurate fit when focusing on recent data.

VAR’s Superiority: Despite the improvements seen in ARIMAX models using post-COVID data, they fell short of the predictive prowess exhibited by VAR models. This highlighted VAR’s superior ability to interpret and forecast based on the interplay between multiple economic indicators.

Deciphering the Economic Narrative: The Role of Key Variables

Our exploration revealed two variables as particularly influential in forecasting the yearly Consumer Price Index (CPI) in the US: Personal Consumption and Treasury Yield. These variables showcased a high correlation with the CPI, hinting at their pivotal roles in the post-pandemic economic landscape.

Personal Consumption: Reflecting shifts in consumer behavior during the pandemic, this variable has become a critical indicator of economic health.

Treasury Yield: Serving as a barometer for broader economic trends and policies, Treasury Yield’s correlation with CPI underscores its significance in our current economic context.

The Road Ahead: Embracing Change in Economic

Forecasting In conclusion, our analysis not only highlights the VAR(2) model’s adeptness in navigating the post-COVID economic waters but also underscores the imperative to prioritize recent data for more accurate forecasting. The pandemic has irrevocably altered the economic fabric, mandating an adaptive approach to forecasting models and data selection.

Stay tuned as we continue to explore and unravel the complexities of economic forecasting in this ever-changing world.